SAND-framework/application/traitements/authentification-example.php
Emmanuel ROY 41f2c5820b Ajout intégration de l'hybridAuthentification encore en état de code brut
Pas de tests

TODO: aller chercher les token et les id des authentifcation pour google, github, facebook, twitter ... Reste a tester et à décider pour les autres types d'authentification.
2019-09-26 04:27:05 +02:00

57 lines
1.8 KiB
PHP

<?php
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
try {
//Feed configuration array to Hybridauth
$hybridauth = new \Hybridauth\Hybridauth($config);
//Then we can proceed and sign in with Twitter as an example. If you want to use a diffirent provider,
//simply replace 'Twitter' with 'Google' or 'Facebook'.
//Attempt to authenticate users with a Twitter provider
$adapter = $hybridauth->authenticate('Twitter');
//Returns a boolean of whether the user is connected with Twitter
$isConnected = $adapter->isConnected();
if ($isConnected == false) {
//Attempt to authenticate users with a Google provider
$adapter = $hybridauth->authenticate('Google');
$isConnected = $adapter->isConnected();
}
if ($isConnected == false) {
//Attempt to authenticate users with a Facebook provider
$adapter = $hybridauth->authenticate('Facebook');
$isConnected = $adapter->isConnected();
}
if ($isConnected == false) {
//Attempt to authenticate users with a Github provider
$adapter = $hybridauth->authenticate('Github');
$isConnected = $adapter->isConnected();
}
if ($isConnected) {
session_start();
//Retrieve the user's token
$token = $adapter->getAccessToken();
$_SESSION['accessToken'] = $token;
//Retrieve the user's profile
$userProfile = $adapter->getUserProfile();
$_SESSION['userProfile'] = $userProfile;
//Disconnect the adapter
$adapter->disconnect();
header("location:" . Url::link_rewrite(false, 'compte', []));
} else {
header("location:" . Url::link_rewrite(false, 'error', []));
}
} catch (\Exception $e) {
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}