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;
|
||||
|
||||
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";
|
||||
|
||||
class Application
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
|
||||
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{
|
||||
|
||||
public $modele;
|
||||
|
|
|
@ -7,6 +7,24 @@ namespace MVC\Classe;
|
|||
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()
|
||||
{
|
||||
if (isset($_SESSION['userProfile'])) {
|
||||
|
|
|
@ -2,18 +2,20 @@
|
|||
|
||||
namespace MVC\Classe;
|
||||
|
||||
//require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."define-constantes.php";
|
||||
|
||||
class Url
|
||||
{
|
||||
public $page;
|
||||
public $registre;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
public $page;
|
||||
public $registre;
|
||||
|
||||
//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['name'] = 'accueil';
|
||||
$page['description'] = "";
|
||||
|
@ -21,7 +23,6 @@ class Url
|
|||
$page['control'] = false;
|
||||
|
||||
|
||||
|
||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$urlTrim = trim( $url['path'] , '/' );
|
||||
$urlParts = explode('/' , $urlTrim );
|
||||
|
@ -55,11 +56,11 @@ class Url
|
|||
$this->page = $page;
|
||||
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 ) {
|
||||
$values = array();
|
||||
$keys = array();
|
||||
foreach( $urlParts as $key => $value ){
|
||||
foreach($urlParts as $key => $value ){
|
||||
if($key%2 == 0) {
|
||||
$values[] = $value;
|
||||
} else {
|
||||
|
|
|
@ -5,28 +5,28 @@
|
|||
*/
|
||||
$config = [
|
||||
//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' => [
|
||||
'GitHub' => [
|
||||
'enabled' => true,
|
||||
'keys' => ['id' => '', 'secret' => ''],
|
||||
'keys' => ['id' => '4cc55bcafbf8ea77ae14', 'secret' => 'e0b7c5091d7af4f4e5ced843f2e8ce1f38f02578'],
|
||||
],
|
||||
|
||||
'Google' => [
|
||||
'enabled' => true,
|
||||
'keys' => ['id' => '', 'secret' => ''],
|
||||
'keys' => ['id' => '686670374445-mhktaj9gp08p6oiu8e1aue3ckua6e3s3.apps.googleusercontent.com', 'secret' => '4yOeNxYuYE4H8DFhVzQlOb_U'],
|
||||
],
|
||||
|
||||
'Facebook' => [
|
||||
'enabled' => true,
|
||||
'keys' => ['id' => '', 'secret' => ''],
|
||||
'keys' => ['id' => '432266300978748', 'secret' => '43815184db62771fce19b64cdd80110a'],
|
||||
],
|
||||
|
||||
'Twitter' => [
|
||||
'enabled' => true,
|
||||
'keys' => ['key' => '', 'secret' => ''],
|
||||
'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'],
|
||||
]
|
||||
],
|
||||
//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
|
||||
\MVC\Session::isregistered();
|
||||
|
||||
\MVC\Classe\Session::start();
|
||||
//\MVC\Classe\Session::isregistered();
|
||||
|
||||
require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
|
||||
|
||||
|
@ -8,11 +10,12 @@ $adapters = $hybridauth->getConnectedAdapters();
|
|||
|
||||
$templateData['adapters'] = $adapters;
|
||||
|
||||
$templateData['extractedData'] = [
|
||||
/*$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'] = [];
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
@section('top-css')
|
||||
@endsection
|
||||
|
||||
@section('top-javascript')
|
||||
@endsection
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@section('top-javascript')
|
||||
@show
|
||||
|
||||
@yield('body')
|
||||
|
||||
@section('bottom-javascript')
|
||||
@endsection
|
||||
@show
|
||||
|
||||
</body>
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
@section('content')
|
||||
<h1>Accueil</h1>
|
||||
<br /><br /><br />
|
||||
<a href="{{ \MVC\Classe\Url::link_rewrite(false, 'authentification', []) }}">S'authentifier ?</a>
|
||||
<hr/>
|
||||
{{$templating_a}}::{{$templating_b}}::{{$templating_c}}
|
||||
|
||||
@endsection
|
||||
|
|
|
@ -19,15 +19,16 @@
|
|||
</li>
|
||||
@endif
|
||||
@endforeach
|
||||
<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>
|
||||
</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('{{ \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>
|
||||
<strong>{{$adapter->getUserProfile()->displayName }}</strong> from
|
||||
<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>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* 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";
|
||||
|
||||
|
@ -20,9 +20,9 @@ try {
|
|||
// Validate provider exists in the $config
|
||||
if (in_array($url_params['provider'], $hybridauth->getProviders())) {
|
||||
// Store the provider for the callback event
|
||||
$storage->set('provider', $_GET['provider']);
|
||||
$storage->set('provider', $url_params['provider']);
|
||||
} else {
|
||||
$error = $_GET['provider'];
|
||||
$error = $url_params['provider'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ try {
|
|||
//
|
||||
// Handle invalid provider errors
|
||||
//
|
||||
if ($error) {
|
||||
if ($error !== false) {
|
||||
error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config');
|
||||
// Close the pop-up window
|
||||
echo "
|
||||
|
@ -56,22 +56,32 @@ try {
|
|||
//
|
||||
// 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);
|
||||
|
||||
// Retrieve the provider record
|
||||
$adapter = $hybridauth->getAdapter($provider);
|
||||
$userProfile = $adapter->getUserProfile();
|
||||
$accessToken = $adapter->getAccessToken();
|
||||
$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());
|
||||
|
||||
// Close pop-up window
|
||||
echo "
|
||||
echo <<<EOD
|
||||
|
||||
<script>
|
||||
window.opener.location.reload();
|
||||
window.close();
|
||||
</script>";
|
||||
window.opener.location.assign('compte');
|
||||
self.close();
|
||||
</script>
|
||||
EOD;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
{
|
||||
"autoload": {
|
||||
"files": [
|
||||
"./application/config/define-constantes.php"
|
||||
],
|
||||
|
||||
"psr-4": {
|
||||
"MVC\\Classe\\":"./application/class",
|
||||
"MVC\\Objets\\":"./application/objets"
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
error_reporting(-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";
|
||||
|
||||
$poo_v5 = new \MVC\Classe\Application();
|
||||
|
|
Loading…
Reference in a new issue