This commit is contained in:
Jaybe
2025-03-05 14:10:06 +09:00
commit 7a77932344
1905 changed files with 122510 additions and 0 deletions
@@ -0,0 +1,59 @@
<?php
/**
* A simple example that shows how to use multiple providers.
*/
include 'vendor/autoload.php';
include 'config.php';
use Hybridauth\Exception\Exception;
use Hybridauth\Hybridauth;
use Hybridauth\HttpClient;
use Hybridauth\Storage\Session;
try {
/**
* Feed configuration array to Hybridauth.
*/
$hybridauth = new Hybridauth($config);
/**
* Initialize session storage.
*/
$storage = new Session();
/**
* Hold information about provider when user clicks on Sign In.
*/
if (isset($_GET['provider'])) {
$storage->set('provider', $_GET['provider']);
}
/**
* When provider exists in the storage, try to authenticate user and clear storage.
*
* When invoked, `authenticate()` will redirect users to provider login page where they
* will be asked to grant access to your application. If they do, provider will redirect
* the users back to Authorization callback URL (i.e., this script).
*/
if ($provider = $storage->get('provider')) {
$hybridauth->authenticate($provider);
$storage->set('provider', null);
}
/**
* This will erase the current user authentication data from session, and any further
* attempt to communicate with provider.
*/
if (isset($_GET['logout'])) {
$adapter = $hybridauth->getAdapter($_GET['logout']);
$adapter->disconnect();
}
/**
* Redirects user to home page (i.e., index.php in our case)
*/
HttpClient\Util::redirect('https://path/to/hybridauth/examples/example_06');
} catch (Exception $e) {
echo $e->getMessage();
}
@@ -0,0 +1,35 @@
<?php
/**
* Build a configuration array to pass to `Hybridauth\Hybridauth`
*/
$config = [
/**
* Set the Authorization callback URL to https://path/to/hybridauth/examples/example_06/callback.php.
* Understandably, you need to replace 'path/to/hybridauth' with the real path to this script.
*/
'callback' => 'https://path/to/hybridauth/examples/example_06/callback.php',
'providers' => [
'Twitter' => [
'enabled' => true,
'keys' => [
'key' => '...',
'secret' => '...',
],
],
'LinkedIn' => [
'enabled' => true,
'keys' => [
'id' => '...',
'secret' => '...',
],
],
'Facebook' => [
'enabled' => true,
'keys' => [
'id' => '...',
'secret' => '...',
],
],
],
];
@@ -0,0 +1,49 @@
<?php
/**
* Build a simple HTML page with multiple providers.
*/
include 'vendor/autoload.php';
include 'config.php';
use Hybridauth\Hybridauth;
$hybridauth = new Hybridauth($config);
$adapters = $hybridauth->getConnectedAdapters();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example 06</title>
</head>
<body>
<h1>Sign in</h1>
<ul>
<?php foreach ($hybridauth->getProviders() as $name) : ?>
<?php if (!isset($adapters[$name])) : ?>
<li>
<a href="<?php print $config['callback'] . "?provider={$name}"; ?>">
Sign in with <strong><?php print $name; ?></strong>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php if ($adapters) : ?>
<h1>You are logged in:</h1>
<ul>
<?php foreach ($adapters as $name => $adapter) : ?>
<li>
<strong><?php print $adapter->getUserProfile()->displayName; ?></strong> from
<i><?php print $name; ?></i>
<span>(<a href="<?php print $config['callback'] . "?logout={$name}"; ?>">Log Out</a>)</span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</body>
</html>