Ajout des token et pasphrase des 4 hybrid authentifaction choisie: Github,Facebook,Google,Twitter
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
This commit is contained in:
parent
41f2c5820b
commit
e758c5fcb1
|
@ -2,10 +2,6 @@
|
||||||
|
|
||||||
namespace MVC\Classe;
|
namespace MVC\Classe;
|
||||||
|
|
||||||
define( "CONTROLLERS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
|
|
||||||
define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config");
|
|
||||||
define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs");
|
|
||||||
|
|
||||||
require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php";
|
require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php";
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
namespace MVC\Classe;
|
namespace MVC\Classe;
|
||||||
|
|
||||||
define( "MODELS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles");
|
|
||||||
define( "VIEW_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues");
|
|
||||||
define( "CONTROLLER_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
|
|
||||||
define( "TRAITEMENT_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements");
|
|
||||||
|
|
||||||
class Controlleur{
|
class Controlleur{
|
||||||
|
|
||||||
public $modele;
|
public $modele;
|
||||||
|
|
|
@ -7,6 +7,24 @@ namespace MVC\Classe;
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static public function start()
|
||||||
|
{
|
||||||
|
session_start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function setUserProfile($userProfile)
|
||||||
|
{
|
||||||
|
$_SESSION['userProfile'] = $userProfile;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public function setToken($token)
|
||||||
|
{
|
||||||
|
$_SESSION['userToken'] = $token;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static public function isRegistered()
|
static public function isRegistered()
|
||||||
{
|
{
|
||||||
if (isset($_SESSION['userProfile'])) {
|
if (isset($_SESSION['userProfile'])) {
|
||||||
|
|
|
@ -2,18 +2,20 @@
|
||||||
|
|
||||||
namespace MVC\Classe;
|
namespace MVC\Classe;
|
||||||
|
|
||||||
|
//require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."define-constantes.php";
|
||||||
|
|
||||||
class Url
|
class Url
|
||||||
{
|
{
|
||||||
public $page;
|
public $page;
|
||||||
public $registre;
|
public $registre;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(){
|
|
||||||
|
|
||||||
//on créé le registre des modules symfony
|
|
||||||
$this->registre = new \MVC\Classe\ModularRegister();
|
|
||||||
|
|
||||||
//définition des parametres de base
|
public function __construct(){
|
||||||
|
|
||||||
|
//on créé le registre des modules symfony
|
||||||
|
$this->registre = new \MVC\Classe\ModularRegister();
|
||||||
|
|
||||||
|
//définition des parametres de base
|
||||||
$page = array();
|
$page = array();
|
||||||
$page['name'] = 'accueil';
|
$page['name'] = 'accueil';
|
||||||
$page['description'] = "";
|
$page['description'] = "";
|
||||||
|
@ -21,7 +23,6 @@ class Url
|
||||||
$page['control'] = false;
|
$page['control'] = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||||
$urlTrim = trim( $url['path'] , '/' );
|
$urlTrim = trim( $url['path'] , '/' );
|
||||||
$urlParts = explode('/' , $urlTrim );
|
$urlParts = explode('/' , $urlTrim );
|
||||||
|
@ -55,11 +56,11 @@ class Url
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//cas d'utilisation normal : il existe autant de clé que de valeurs
|
//cas d'utilisation normal : il existe autant de clé que de valeurs
|
||||||
} else if ( $numParts != 0 ) {
|
} else if ( $numParts != 0 ) {
|
||||||
$values = array();
|
$values = array();
|
||||||
$keys = array();
|
$keys = array();
|
||||||
foreach( $urlParts as $key => $value ){
|
foreach($urlParts as $key => $value ){
|
||||||
if($key%2 == 0) {
|
if($key%2 == 0) {
|
||||||
$values[] = $value;
|
$values[] = $value;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,28 +5,28 @@
|
||||||
*/
|
*/
|
||||||
$config = [
|
$config = [
|
||||||
//Location where to redirect users once they authenticate with a provider
|
//Location where to redirect users once they authenticate with a provider
|
||||||
'callback' => \MVC\Url::link_rewrite(false, 'accueil', []),
|
'callback' => 'http://localhost:8080/' . \MVC\Classe\Url::link_rewrite(false, 'compte', []),
|
||||||
|
|
||||||
//Providers specifics
|
//Providers specifics
|
||||||
'providers' => [
|
'providers' => [
|
||||||
'GitHub' => [
|
'GitHub' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'keys' => ['id' => '', 'secret' => ''],
|
'keys' => ['id' => '4cc55bcafbf8ea77ae14', 'secret' => 'e0b7c5091d7af4f4e5ced843f2e8ce1f38f02578'],
|
||||||
],
|
],
|
||||||
|
|
||||||
'Google' => [
|
'Google' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'keys' => ['id' => '', 'secret' => ''],
|
'keys' => ['id' => '686670374445-mhktaj9gp08p6oiu8e1aue3ckua6e3s3.apps.googleusercontent.com', 'secret' => '4yOeNxYuYE4H8DFhVzQlOb_U'],
|
||||||
],
|
],
|
||||||
|
|
||||||
'Facebook' => [
|
'Facebook' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'keys' => ['id' => '', 'secret' => ''],
|
'keys' => ['id' => '432266300978748', 'secret' => '43815184db62771fce19b64cdd80110a'],
|
||||||
],
|
],
|
||||||
|
|
||||||
'Twitter' => [
|
'Twitter' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'keys' => ['key' => '', 'secret' => ''],
|
'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
//optional : set debug mode
|
//optional : set debug mode
|
||||||
|
|
10
application/config/define-constantes.php
Normal file
10
application/config/define-constantes.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
define("APPLICATION_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "application");
|
||||||
|
define("MODULES_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules");
|
||||||
|
define("CONTROLLERS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
|
||||||
|
define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config");
|
||||||
|
define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs");
|
||||||
|
define("MODELS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles");
|
||||||
|
define("VIEW_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues");
|
||||||
|
define("CONTROLLER_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
|
||||||
|
define("TRAITEMENT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements");
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
\MVC\Session::isregistered();
|
|
||||||
|
\MVC\Classe\Session::start();
|
||||||
|
//\MVC\Classe\Session::isregistered();
|
||||||
|
|
||||||
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
||||||
|
|
||||||
|
@ -8,11 +10,12 @@ $adapters = $hybridauth->getConnectedAdapters();
|
||||||
|
|
||||||
$templateData['adapters'] = $adapters;
|
$templateData['adapters'] = $adapters;
|
||||||
|
|
||||||
$templateData['extractedData'] = [
|
/*$templateData['extractedData'] = [
|
||||||
'token' => $_SESSION['userToken'],
|
'token' => $_SESSION['userToken'],
|
||||||
'identifier' => $_SESSION['userProfile']->identifier,
|
'identifier' => $_SESSION['userProfile']->identifier,
|
||||||
'email' => $_SESSION['userProfile']->email,
|
'email' => $_SESSION['userProfile']->email,
|
||||||
'first_name' => $_SESSION['userProfile']->firstName,
|
'first_name' => $_SESSION['userProfile']->firstName,
|
||||||
'last_name' => $_SESSION['userProfile']->lastName,
|
'last_name' => $_SESSION['userProfile']->lastName,
|
||||||
'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'),
|
'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'),
|
||||||
];
|
];*/
|
||||||
|
$templateData['extractedData'] = [];
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
@section('top-css')
|
@section('top-css')
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('top-javascript')
|
|
||||||
@endsection
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
@section('top-javascript')
|
||||||
|
@show
|
||||||
|
|
||||||
@yield('body')
|
@yield('body')
|
||||||
|
|
||||||
@section('bottom-javascript')
|
@section('bottom-javascript')
|
||||||
@endsection
|
@show
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
@section('content')
|
@section('content')
|
||||||
<h1>Accueil</h1>
|
<h1>Accueil</h1>
|
||||||
<br /><br /><br />
|
<br /><br /><br />
|
||||||
|
<a href="{{ \MVC\Classe\Url::link_rewrite(false, 'authentification', []) }}">S'authentifier ?</a>
|
||||||
|
<hr/>
|
||||||
{{$templating_a}}::{{$templating_b}}::{{$templating_c}}
|
{{$templating_a}}::{{$templating_b}}::{{$templating_c}}
|
||||||
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
@ -19,15 +19,16 @@
|
||||||
</li>
|
</li>
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
<ul>
|
</ul>
|
||||||
@endsection
|
|
||||||
|
|
||||||
@section('top-javascript')
|
|
||||||
<script>
|
|
||||||
function auth_popup(provider) {
|
|
||||||
// replace 'path/to/hybridauth' with the real path to this script
|
|
||||||
var authWindow = window.open('/control/authentification-callback-example/provider/' + provider, 'authWindow', 'width=600,height=400,scrollbars=yes');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
@section('top-javascript')
|
||||||
|
<script>
|
||||||
|
function auth_popup(provider) {
|
||||||
|
// replace 'path/to/hybridauth' with the real path to this script
|
||||||
|
var authWindow = window.open('{{ \MVC\Classe\Url::link_rewrite(true, 'authentification-callback-example', []) }}/provider/' + provider, 'authWindow', 'width=600,height=400,scrollbars=yes');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
<li>
|
<li>
|
||||||
<strong>{{$adapter->getUserProfile()->displayName }}</strong> from
|
<strong>{{$adapter->getUserProfile()->displayName }}</strong> from
|
||||||
<i>{{ $name }}</i>
|
<i>{{ $name }}</i>
|
||||||
<span>(<a href="{{$config['callback'] }}?logout={{ $name }}" ; ?>">Log Out</a>)</span>
|
<span>(<a href="{{ \MVC\Classe\Url::link_rewrite( true, 'authentification-callback-example', ['logout'=>$name ]) }}"
|
||||||
|
; ?>">Log Out</a>)</span>
|
||||||
</li>
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* A simple example that shows how to use multiple providers, opening provider authentication in a pop-up.
|
* A simple example that shows how to use multiple providers, opening provider authentication in a pop-up.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Hybridauth\Hybridauth;
|
use MVC\Classe\Dumper;
|
||||||
|
|
||||||
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ try {
|
||||||
// Validate provider exists in the $config
|
// Validate provider exists in the $config
|
||||||
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', $_GET['provider']);
|
$storage->set('provider', $url_params['provider']);
|
||||||
} else {
|
} else {
|
||||||
$error = $_GET['provider'];
|
$error = $url_params['provider'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ try {
|
||||||
//
|
//
|
||||||
// Handle invalid provider errors
|
// Handle invalid provider errors
|
||||||
//
|
//
|
||||||
if ($error) {
|
if ($error !== false) {
|
||||||
error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config');
|
error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config');
|
||||||
// Close the pop-up window
|
// Close the pop-up window
|
||||||
echo "
|
echo "
|
||||||
|
@ -56,22 +56,32 @@ try {
|
||||||
//
|
//
|
||||||
// Event 3: Provider returns via CALLBACK
|
// Event 3: Provider returns via CALLBACK
|
||||||
//
|
//
|
||||||
if ($provider = $storage->get('provider')) {
|
if ($url_params['provider'] = $storage->get('provider')) {
|
||||||
|
|
||||||
$hybridauth->authenticate($provider);
|
$hybridauth->authenticate($url_params['provider']);
|
||||||
|
|
||||||
|
die('OK!');
|
||||||
$storage->set('provider', null);
|
$storage->set('provider', null);
|
||||||
|
|
||||||
// Retrieve the provider record
|
// Retrieve the provider record
|
||||||
$adapter = $hybridauth->getAdapter($provider);
|
$adapter = $hybridauth->getAdapter($url_params['provider']);
|
||||||
$userProfile = $adapter->getUserProfile();
|
|
||||||
$accessToken = $adapter->getAccessToken();
|
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
|
// Close pop-up window
|
||||||
echo "
|
echo <<<EOD
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.opener.location.reload();
|
window.opener.location.assign('compte');
|
||||||
window.close();
|
self.close();
|
||||||
</script>";
|
</script>
|
||||||
|
EOD;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
{
|
{
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"./application/config/define-constantes.php"
|
||||||
|
],
|
||||||
|
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"MVC\\Classe\\":"./application/class",
|
"MVC\\Classe\\":"./application/class",
|
||||||
"MVC\\Objets\\":"./application/objets"
|
"MVC\\Objets\\":"./application/objets"
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
|
||||||
define("APPLICATION_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."application");
|
|
||||||
define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor");
|
|
||||||
define("MODULES_PATH", APPLICATION_PATH.DIRECTORY_SEPARATOR."modules");
|
|
||||||
|
|
||||||
|
define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor");
|
||||||
require VENDOR_PATH.DIRECTORY_SEPARATOR."autoload.php";
|
require VENDOR_PATH.DIRECTORY_SEPARATOR."autoload.php";
|
||||||
|
|
||||||
$poo_v5 = new \MVC\Classe\Application();
|
$poo_v5 = new \MVC\Classe\Application();
|
||||||
|
|
Loading…
Reference in a new issue