e758c5fcb1
Fonctionne partiellement pour des raisons obscure lié a cette authentification partagée par des grands groupe. TODO: lire les documentation officielles provenant des 4 plate-formes tranquillement afin de ccomprendre commet doit on tester ces type d'auth quitte a créé un sous domaine particulier directement hebergé sur gittea -->Sécuriser le serveur de dev
92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* A simple example that shows how to use multiple providers, opening provider authentication in a pop-up.
|
|
*/
|
|
|
|
use MVC\Classe\Dumper;
|
|
|
|
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
|
|
|
try {
|
|
|
|
$hybridauth = new Hybridauth\Hybridauth($config);
|
|
$storage = new Hybridauth\Storage\Session();
|
|
$error = false;
|
|
|
|
//
|
|
// Event 1: User clicked SIGN-IN link
|
|
//
|
|
if (isset($url_params['provider'])) {
|
|
// Validate provider exists in the $config
|
|
if (in_array($url_params['provider'], $hybridauth->getProviders())) {
|
|
// Store the provider for the callback event
|
|
$storage->set('provider', $url_params['provider']);
|
|
} else {
|
|
$error = $url_params['provider'];
|
|
}
|
|
}
|
|
|
|
//
|
|
// Event 2: User clicked LOGOUT link
|
|
//
|
|
if (isset($url_params['logout'])) {
|
|
if (in_array($url_params['logout'], $hybridauth->getProviders())) {
|
|
// Disconnect the adapter
|
|
$adapter = $hybridauth->getAdapter($url_params['logout']);
|
|
$adapter->disconnect();
|
|
} else {
|
|
$error = $url_params['logout'];
|
|
}
|
|
}
|
|
|
|
//
|
|
// Handle invalid provider errors
|
|
//
|
|
if ($error !== false) {
|
|
error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config');
|
|
// Close the pop-up window
|
|
echo "
|
|
<script>
|
|
window.opener.location.reload();
|
|
window.close();
|
|
</script>";
|
|
exit;
|
|
}
|
|
|
|
//
|
|
// Event 3: Provider returns via CALLBACK
|
|
//
|
|
if ($url_params['provider'] = $storage->get('provider')) {
|
|
|
|
$hybridauth->authenticate($url_params['provider']);
|
|
|
|
die('OK!');
|
|
$storage->set('provider', null);
|
|
|
|
// Retrieve the provider record
|
|
$adapter = $hybridauth->getAdapter($url_params['provider']);
|
|
|
|
Dumper::dump($adapter->getUserProfile());
|
|
Dumper::dump($adapter->getAccessToken());
|
|
|
|
|
|
\MVC\Classe\Session::start();
|
|
\MVC\Classe\Session::setUserProfile($adapter->getUserProfile());
|
|
\MVC\Classe\Session::setToken($adapter->getAccessToken());
|
|
|
|
// Close pop-up window
|
|
echo <<<EOD
|
|
|
|
<script>
|
|
window.opener.location.assign('compte');
|
|
self.close();
|
|
</script>
|
|
EOD;
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
error_log($e->getMessage());
|
|
echo $e->getMessage();
|
|
}
|