From 42ef646e87a60d7312578f8aa56faa5962cce8cb Mon Sep 17 00:00:00 2001 From: Emmanuel ROY Date: Thu, 19 Mar 2020 16:57:14 +0100 Subject: [PATCH] =?UTF-8?q?Test=20sur=20l'impl=C3=A9mentation=20de=20hybri?= =?UTF-8?q?dAuth=20->=20ne=20recoit=20pas=20les=20donn=C3=A9es=20utilisate?= =?UTF-8?q?ur=20mais=20par=20contre=20se=20connecte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .idea/SAND-framework.iml | 4 +- .idea/php.xml | 4 +- application/class/Session.php | 20 ++++ .../authentification-config-example.php | 2 +- .../include/controlleurs/authentificate.php | 94 +++++++++++++++++++ .../include/controlleurs/authentification.php | 2 + application/include/controlleurs/compte.php | 27 +++--- application/include/controlleurs/logout.php | 48 ++++++++++ .../include/modeles/authentificate.model | 4 + application/include/modeles/logout.model | 4 + .../vues/view/authentificate.blade.php | 14 +++ .../vues/view/authentification.blade.php | 3 +- .../include/vues/view/compte.blade.php | 13 +-- application/parameters.php | 2 +- .../authentification-callback-example.php | 26 +++-- composer.json | 2 +- 16 files changed, 231 insertions(+), 38 deletions(-) create mode 100644 application/include/controlleurs/authentificate.php create mode 100644 application/include/controlleurs/logout.php create mode 100644 application/include/modeles/authentificate.model create mode 100644 application/include/modeles/logout.model create mode 100644 application/include/vues/view/authentificate.blade.php diff --git a/.idea/SAND-framework.iml b/.idea/SAND-framework.iml index 7105966..16440b1 100644 --- a/.idea/SAND-framework.iml +++ b/.idea/SAND-framework.iml @@ -12,9 +12,8 @@ - - + @@ -29,6 +28,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index 5183468..7efcc83 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -31,8 +31,8 @@ - - + + diff --git a/application/class/Session.php b/application/class/Session.php index 938e459..de8f97f 100644 --- a/application/class/Session.php +++ b/application/class/Session.php @@ -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'])) { diff --git a/application/config/authentification-config-example.php b/application/config/authentification-config-example.php index 6acacf7..d42f7bd 100644 --- a/application/config/authentification-config-example.php +++ b/application/config/authentification-config-example.php @@ -29,7 +29,7 @@ $config = [ 'Twitter' => [ 'enabled' => true, - 'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'], + 'keys' => ['key' => 'gnsmsVW0EkdpSVeqwCOG7V1H5', 'secret' => 'cdv71bFMUV4OBpkjFIwPNOlbRBQhrAaWBTmLF8aPzZBeMf3PyQ'], ] ], //optional : set debug mode diff --git a/application/include/controlleurs/authentificate.php b/application/include/controlleurs/authentificate.php new file mode 100644 index 0000000..20ee0fc --- /dev/null +++ b/application/include/controlleurs/authentificate.php @@ -0,0 +1,94 @@ +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 " + "; + 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 << + window.opener.location.href = '$compte'; + window.close(); + +EOD; + */ + + + + + } + +} catch (Exception $e) { + error_log($e->getMessage()); + echo $e->getMessage(); +} diff --git a/application/include/controlleurs/authentification.php b/application/include/controlleurs/authentification.php index c6431e4..5c2b45b 100644 --- a/application/include/controlleurs/authentification.php +++ b/application/include/controlleurs/authentification.php @@ -1,5 +1,7 @@ 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]; diff --git a/application/include/controlleurs/logout.php b/application/include/controlleurs/logout.php new file mode 100644 index 0000000..5fff399 --- /dev/null +++ b/application/include/controlleurs/logout.php @@ -0,0 +1,48 @@ +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 " + "; + exit; + } + + + +} catch (Exception $e) { + error_log($e->getMessage()); + echo $e->getMessage(); +} diff --git a/application/include/modeles/authentificate.model b/application/include/modeles/authentificate.model new file mode 100644 index 0000000..7cd2d33 --- /dev/null +++ b/application/include/modeles/authentificate.model @@ -0,0 +1,4 @@ +name : authentificate +page_title: Hybrid Authentification de l'application +description : La page d'authentification +params : params diff --git a/application/include/modeles/logout.model b/application/include/modeles/logout.model new file mode 100644 index 0000000..e9167c7 --- /dev/null +++ b/application/include/modeles/logout.model @@ -0,0 +1,4 @@ +name : logout +page_title: Hybrid Authentification de l'application +description : La page d'authentification +params : params diff --git a/application/include/vues/view/authentificate.blade.php b/application/include/vues/view/authentificate.blade.php new file mode 100644 index 0000000..285e2d2 --- /dev/null +++ b/application/include/vues/view/authentificate.blade.php @@ -0,0 +1,14 @@ +@extends('body') + +@section('sidebar') + +@endsection + +@section('content') + +@endsection + +@section('top-javascript') + +@endsection + diff --git a/application/include/vues/view/authentification.blade.php b/application/include/vues/view/authentification.blade.php index 2dec8d7..67d7732 100644 --- a/application/include/vues/view/authentification.blade.php +++ b/application/include/vues/view/authentification.blade.php @@ -13,7 +13,8 @@ @foreach ($hybridauth->getProviders() as $name) @if (!isset($adapters[$name]))
  • - + + Sign in with {{ $name }}
  • diff --git a/application/include/vues/view/compte.blade.php b/application/include/vues/view/compte.blade.php index b040543..22d9783 100644 --- a/application/include/vues/view/compte.blade.php +++ b/application/include/vues/view/compte.blade.php @@ -10,19 +10,16 @@

    Compte utilisateur

    - @foreach ($extractedData as $key => $value) - {{ $key }} :: {{ $value }} - @endforeach - @if ($adapters)

    You are logged in:

      @foreach ($adapters as $name => $adapter)
    • - {{$adapter->getUserProfile()->displayName }} from - {{ $name }} - (">Log Out) + from {{ $name }} + {{ \MVC\Classe\Dumper::dump($adapter) }} + + (Log Out)
    • @endforeach
    diff --git a/application/parameters.php b/application/parameters.php index ba9983d..d86fad6 100644 --- a/application/parameters.php +++ b/application/parameters.php @@ -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/"); \ No newline at end of file +define('PATH_URL',$_SERVER['REQUEST_SCHEME'] . "://www.sand-framework.infoartsmedia.org"); \ No newline at end of file diff --git a/application/traitements/authentification-callback-example.php b/application/traitements/authentification-callback-example.php index 1b9aab6..73b0949 100644 --- a/application/traitements/authentification-callback-example.php +++ b/application/traitements/authentification-callback-example.php @@ -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 << - window.opener.location.assign('compte'); - self.close(); + window.opener.location.href = '$compte'; + window.close(); EOD; + */ + + + } diff --git a/composer.json b/composer.json index b4113bf..bd020c7 100644 --- a/composer.json +++ b/composer.json @@ -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",