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/support" />
<excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/view" /> <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/view" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ircmaxell/password-compat" /> <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/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/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" /> <excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" /> <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-mbstring" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php54" /> <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-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/routing" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" /> <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/service-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-exporter" /> <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/neitanod/forceutf8" />
<path value="$PROJECT_DIR$/vendor/symfony/cache" /> <path value="$PROJECT_DIR$/vendor/symfony/cache" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" /> <path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/johnpbloch/wordpress-core-installer" /> <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
<path value="$PROJECT_DIR$/vendor/johnpbloch/wordpress" /> <path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" /> <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />

View file

@ -25,6 +25,26 @@ class Session
return; 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() static public function isRegistered()
{ {
if (isset($_SESSION['userProfile'])) { if (isset($_SESSION['userProfile'])) {

View file

@ -29,7 +29,7 @@ $config = [
'Twitter' => [ 'Twitter' => [
'enabled' => true, 'enabled' => true,
'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'], 'keys' => ['key' => 'gnsmsVW0EkdpSVeqwCOG7V1H5', 'secret' => 'cdv71bFMUV4OBpkjFIwPNOlbRBQhrAaWBTmLF8aPzZBeMf3PyQ'],
] ]
], ],
//optional : set debug mode //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 <?php
\MVC\Classe\Session::start();
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php"; require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
$hybridauth = new Hybridauth\Hybridauth($config); $hybridauth = new Hybridauth\Hybridauth($config);

View file

@ -5,17 +5,20 @@
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php"; require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
$hybridauth = new Hybridauth\Hybridauth($config); //$hybridauth = new Hybridauth\Hybridauth($config);
$adapters = $hybridauth->getConnectedAdapters(); $hybridauth = \MVC\Classe\Session::getHybridAuth();
//$adapters = $hybridauth->getConnectedAdapters();
$templateData['adapters'] = $adapters; $adapter = $hybridauth->getAdapter(\MVC\Classe\Session::getStorage()->get('provider'));
/*$templateData['extractedData'] = [ \MVC\Classe\Dumper::dump($adapter);
'token' => $_SESSION['userToken'],
'identifier' => $_SESSION['userProfile']->identifier, $isConnected = $adapter->isConnected();
'email' => $_SESSION['userProfile']->email, //Retrieve the user's profile
'first_name' => $_SESSION['userProfile']->firstName, $userProfile = $adapter->getUserProfile();
'last_name' => $_SESSION['userProfile']->lastName,
'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'), //Inspect profile's public attributes
];*/ \MVC\Classe\Dumper::dump($isConnected);
$templateData['extractedData'] = []; \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) @foreach ($hybridauth->getProviders() as $name)
@if (!isset($adapters[$name])) @if (!isset($adapters[$name]))
<li> <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 }} Sign in with {{ $name }}
</a> </a>
</li> </li>

View file

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

View file

@ -13,4 +13,4 @@ define('DSN_BDD2',"mysql:host=localhost;dbname=db2");
define('USER_BDD2',"user2"); define('USER_BDD2',"user2");
define('PASS_BDD2',"pass2"); 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 { try {
\MVC\Classe\Session::start();
$hybridauth = new Hybridauth\Hybridauth($config); $hybridauth = new Hybridauth\Hybridauth($config);
$storage = new Hybridauth\Storage\Session(); $storage = new Hybridauth\Storage\Session();
$error = false; $error = false;
@ -21,6 +23,7 @@ try {
if (in_array($url_params['provider'], $hybridauth->getProviders())) { if (in_array($url_params['provider'], $hybridauth->getProviders())) {
// Store the provider for the callback event // Store the provider for the callback event
$storage->set('provider', $url_params['provider']); $storage->set('provider', $url_params['provider']);
\MVC\Classe\Session::setStorage($storage);
} else { } else {
$error = $url_params['provider']; $error = $url_params['provider'];
} }
@ -53,35 +56,38 @@ try {
exit; exit;
} }
// //
// Event 3: Provider returns via CALLBACK // Event 3: Provider returns via CALLBACK
// //
if ($url_params['provider'] = $storage->get('provider')) { if ($url_params['provider'] = $storage->get('provider')) {
$hybridauth->authenticate($url_params['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 // Retrieve the provider record
$adapter = $hybridauth->getAdapter($url_params['provider']); $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::setUserProfile($adapter->getUserProfile());
\MVC\Classe\Session::setToken($adapter->getAccessToken()); \MVC\Classe\Session::setToken($adapter->getAccessToken());
$compte = $config['callback'];
// Close pop-up window // Close pop-up window
echo <<<EOD echo <<<EOD
<script> <script>
window.opener.location.assign('compte'); window.opener.location.href = '$compte';
self.close(); window.close();
</script> </script>
EOD; EOD;
*/
} }

View file

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