Test sur l'implémentation de hybridAuth -> ne recoit pas les données utilisateur mais par contre se connecte

TODO: créé les pages de blog (sommaire,news) permettant d'afficher les fichiers md
TODO: créer les commandes complétement
TODO: envoyer les bugs wordpress
TODO: corriger le bug de création de la base de donnée pour prestashop
This commit is contained in:
Emmanuel ROY 2020-03-19 16:57:14 +01:00
parent c6391bb44f
commit 42ef646e87
16 changed files with 231 additions and 38 deletions

View file

@ -12,9 +12,8 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/support" />
<excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/view" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ircmaxell/password-compat" />
<excludeFolder url="file://$MODULE_DIR$/vendor/johnpbloch/wordpress" />
<excludeFolder url="file://$MODULE_DIR$/vendor/johnpbloch/wordpress-core-installer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/neitanod/forceutf8" />
<excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/random_compat" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
@ -29,6 +28,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php54" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php55" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php70" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/routing" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-exporter" />

View file

@ -31,8 +31,8 @@
<path value="$PROJECT_DIR$/vendor/neitanod/forceutf8" />
<path value="$PROJECT_DIR$/vendor/symfony/cache" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/johnpbloch/wordpress-core-installer" />
<path value="$PROJECT_DIR$/vendor/johnpbloch/wordpress" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
<path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />

View file

@ -25,6 +25,26 @@ class Session
return;
}
static public function setStorage($hybriauthStorage)
{
$_SESSION['storage'] = $hybriauthStorage;
return;
}
static public function getStorage()
{
return $_SESSION['storage'] ;
}
static public function setHybridAuth($hybriauth)
{
$_SESSION['auth'] = $hybriauth;
return;
}
static public function getHybridAuth()
{
return $_SESSION['auth'] ;
}
static public function isRegistered()
{
if (isset($_SESSION['userProfile'])) {

View file

@ -29,7 +29,7 @@ $config = [
'Twitter' => [
'enabled' => true,
'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'],
'keys' => ['key' => 'gnsmsVW0EkdpSVeqwCOG7V1H5', 'secret' => 'cdv71bFMUV4OBpkjFIwPNOlbRBQhrAaWBTmLF8aPzZBeMf3PyQ'],
]
],
//optional : set debug mode

View file

@ -0,0 +1,94 @@
<?php
use MVC\Classe\Dumper;
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
try {
\MVC\Classe\Session::start();
$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']);
\MVC\Classe\Session::setStorage($storage);
} 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')) {
\MVC\Classe\Session::setHybridAuth($hybridauth);
$hybridauth->authenticate($url_params['provider']);
//Suite à l'authentification il ne permet plus de modifier la page il redirige directement sur le callback
/*
// Retrieve the provider record
$adapter = $hybridauth->getAdapter($url_params['provider']);
\MVC\Classe\Session::setUserProfile($adapter->getUserProfile());
\MVC\Classe\Session::setToken($adapter->getAccessToken());
$compte = $config['callback'];
// Close pop-up window
echo <<<EOD
<script>
window.opener.location.href = '$compte';
window.close();
</script>
EOD;
*/
}
} catch (Exception $e) {
error_log($e->getMessage());
echo $e->getMessage();
}

View file

@ -1,5 +1,7 @@
<?php
\MVC\Classe\Session::start();
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
$hybridauth = new Hybridauth\Hybridauth($config);

View file

@ -5,17 +5,20 @@
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
$hybridauth = new Hybridauth\Hybridauth($config);
$adapters = $hybridauth->getConnectedAdapters();
//$hybridauth = new Hybridauth\Hybridauth($config);
$hybridauth = \MVC\Classe\Session::getHybridAuth();
//$adapters = $hybridauth->getConnectedAdapters();
$templateData['adapters'] = $adapters;
$adapter = $hybridauth->getAdapter(\MVC\Classe\Session::getStorage()->get('provider'));
/*$templateData['extractedData'] = [
'token' => $_SESSION['userToken'],
'identifier' => $_SESSION['userProfile']->identifier,
'email' => $_SESSION['userProfile']->email,
'first_name' => $_SESSION['userProfile']->firstName,
'last_name' => $_SESSION['userProfile']->lastName,
'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'),
];*/
$templateData['extractedData'] = [];
\MVC\Classe\Dumper::dump($adapter);
$isConnected = $adapter->isConnected();
//Retrieve the user's profile
$userProfile = $adapter->getUserProfile();
//Inspect profile's public attributes
\MVC\Classe\Dumper::dump($isConnected);
\MVC\Classe\Dumper::dump($userProfile);
$templateData['adapters'] = [\MVC\Classe\Session::getStorage()->get('provider')=>$adapter];

View file

@ -0,0 +1,48 @@
<?php
use MVC\Classe\Dumper;
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
try {
\MVC\Classe\Session::start();
$hybridauth = new Hybridauth\Hybridauth($config);
$storage = new Hybridauth\Storage\Session();
$error = false;
//
// 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();
header("location: ".MVC\Classe\Url::link_rewrite(false,'accueil'));
} 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;
}
} catch (Exception $e) {
error_log($e->getMessage());
echo $e->getMessage();
}

View file

@ -0,0 +1,4 @@
name : authentificate
page_title: Hybrid Authentification de l'application
description : La page d'authentification
params : params

View file

@ -0,0 +1,4 @@
name : logout
page_title: Hybrid Authentification de l'application
description : La page d'authentification
params : params

View file

@ -0,0 +1,14 @@
@extends('body')
@section('sidebar')
@endsection
@section('content')
@endsection
@section('top-javascript')
@endsection

View file

@ -13,7 +13,8 @@
@foreach ($hybridauth->getProviders() as $name)
@if (!isset($adapters[$name]))
<li>
<a href="#" onclick="javascript:auth_popup('{{ $name }}');">
<!--<a href="#" onclick="javascript:auth_popup('{{ $name }}');">-->
<a href="{{ \MVC\Classe\Url::link_rewrite(false, 'authentificate', ['provider' => $name]) }}">
Sign in with {{ $name }}
</a>
</li>

View file

@ -10,19 +10,16 @@
<h1>Compte utilisateur</h1>
@foreach ($extractedData as $key => $value)
{{ $key }} :: {{ $value }}
@endforeach
@if ($adapters)
<h1>You are logged in:</h1>
<ul>
@foreach ($adapters as $name => $adapter)
<li>
<strong>{{$adapter->getUserProfile()->displayName }}</strong> from
<i>{{ $name }}</i>
<span>(<a href="{{ \MVC\Classe\Url::link_rewrite( true, 'authentification-callback-example', ['logout'=>$name ]) }}"
; ?>">Log Out</a>)</span>
from <i>{{ $name }}</i>
{{ \MVC\Classe\Dumper::dump($adapter) }}
<!--<span>(<a href="{{ \MVC\Classe\Url::link_rewrite( true, 'authentification-callback-example', ['logout'=>$name ]) }}"
">Log Out</a>)</span>-->
<span>(<a href="{{ \MVC\Classe\Url::link_rewrite( false, 'logout', ['logout'=>$name ]) }}">Log Out</a>)</span>
</li>
@endforeach
</ul>

View file

@ -13,4 +13,4 @@ define('DSN_BDD2',"mysql:host=localhost;dbname=db2");
define('USER_BDD2',"user2");
define('PASS_BDD2',"pass2");
define('PATH_URL',$_SERVER['REQUEST_SCHEME'] . "://www.sand-framework.infoartsmedia.org/");
define('PATH_URL',$_SERVER['REQUEST_SCHEME'] . "://www.sand-framework.infoartsmedia.org");

View file

@ -9,6 +9,8 @@ require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php
try {
\MVC\Classe\Session::start();
$hybridauth = new Hybridauth\Hybridauth($config);
$storage = new Hybridauth\Storage\Session();
$error = false;
@ -21,6 +23,7 @@ try {
if (in_array($url_params['provider'], $hybridauth->getProviders())) {
// Store the provider for the callback event
$storage->set('provider', $url_params['provider']);
\MVC\Classe\Session::setStorage($storage);
} else {
$error = $url_params['provider'];
}
@ -53,35 +56,38 @@ try {
exit;
}
//
// Event 3: Provider returns via CALLBACK
//
if ($url_params['provider'] = $storage->get('provider')) {
$hybridauth->authenticate($url_params['provider']);
//Suite à l'authentification il ne permet plus de modifier la page il redirige directement sur le callback
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());
$compte = $config['callback'];
// Close pop-up window
echo <<<EOD
<script>
window.opener.location.assign('compte');
self.close();
window.opener.location.href = '$compte';
window.close();
</script>
EOD;
*/
}

View file

@ -15,7 +15,7 @@
"ext-curl": "*",
"windwalker/renderer": "3.*",
"illuminate/view": "4.*",
"hybridauth/hybridauth": "~3.0",
"hybridauth/hybridauth": "^3.2",
"neitanod/forceutf8": "^2.0",
"symfony/routing": "3.4.36",
"symfony/http-foundation": "~2.8",