Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

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

Emmanuel ROY authored on 11/10/2019 15:26:22
Showing 14 changed files
... ...
@@ -2,10 +2,6 @@
2 2
 
3 3
 namespace MVC\Classe;
4 4
 
5
-define( "CONTROLLERS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
6
-define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config");
7
-define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs");
8
-
9 5
 require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php";
10 6
 
11 7
 class Application
... ...
@@ -2,11 +2,6 @@
2 2
 
3 3
 namespace MVC\Classe;
4 4
 
5
-define( "MODELS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles");
6
-define( "VIEW_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues");
7
-define( "CONTROLLER_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
8
-define( "TRAITEMENT_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements");
9
-
10 5
 class Controlleur{
11 6
 	
12 7
 	public $modele;
... ...
@@ -7,6 +7,24 @@ namespace MVC\Classe;
7 7
 class Session
8 8
 {
9 9
 
10
+    static public function start()
11
+    {
12
+        session_start();
13
+        return;
14
+    }
15
+
16
+    static public function setUserProfile($userProfile)
17
+    {
18
+        $_SESSION['userProfile'] = $userProfile;
19
+        return;
20
+    }
21
+
22
+    static public function setToken($token)
23
+    {
24
+        $_SESSION['userToken'] = $token;
25
+        return;
26
+    }
27
+
10 28
     static public function isRegistered()
11 29
     {
12 30
         if (isset($_SESSION['userProfile'])) {
... ...
@@ -2,18 +2,20 @@
2 2
 
3 3
 namespace MVC\Classe;
4 4
 
5
+//require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."define-constantes.php";
6
+
5 7
 class Url
6 8
 {
7
-	public $page;
8
-	public $registre;
9
-	
10
-	
11
-	public function __construct(){
9
+    public $page;
10
+    public $registre;
11
+
12 12
 
13
-	    //on créé le registre des modules symfony
14
-	    $this->registre = new \MVC\Classe\ModularRegister();
13
+    public function __construct(){
15 14
 
16
-	    //définition des parametres de base
15
+        //on créé le registre des modules symfony
16
+        $this->registre = new \MVC\Classe\ModularRegister();
17
+
18
+        //définition des parametres de base
17 19
         $page = array();
18 20
         $page['name'] = 'accueil';
19 21
         $page['description'] = "";
... ...
@@ -21,7 +23,6 @@ class Url
21 23
         $page['control'] = false;
22 24
 
23 25
 
24
-
25 26
         $url = parse_url($_SERVER['REQUEST_URI']);
26 27
         $urlTrim = trim( $url['path'] , '/' );
27 28
         $urlParts = explode('/' , $urlTrim );
... ...
@@ -55,11 +56,11 @@ class Url
55 56
                 $this->page = $page;
56 57
                 return;
57 58
             }
58
-        //cas d'utilisation normal : il existe autant de clé que de valeurs
59
+            //cas d'utilisation normal : il existe autant de clé que de valeurs
59 60
         } else if ( $numParts != 0 ) {
60 61
             $values = array();
61 62
             $keys = array();
62
-            foreach( $urlParts as $key => $value ){
63
+            foreach($urlParts as $key => $value ){
63 64
                 if($key%2 == 0) {
64 65
                     $values[] = $value;
65 66
                 } else {
... ...
@@ -5,28 +5,28 @@
5 5
  */
6 6
 $config = [
7 7
 //Location where to redirect users once they authenticate with a provider
8
-    'callback' => \MVC\Url::link_rewrite(false, 'accueil', []),
8
+    'callback' => 'http://localhost:8080/' . \MVC\Classe\Url::link_rewrite(false, 'compte', []),
9 9
 
10 10
 //Providers specifics
11 11
     'providers' => [
12 12
         'GitHub' => [
13 13
             'enabled' => true,
14
-            'keys' => ['id' => '', 'secret' => ''],
14
+            'keys' => ['id' => '4cc55bcafbf8ea77ae14', 'secret' => 'e0b7c5091d7af4f4e5ced843f2e8ce1f38f02578'],
15 15
         ],
16 16
 
17 17
         'Google' => [
18 18
             'enabled' => true,
19
-            'keys' => ['id' => '', 'secret' => ''],
19
+            'keys' => ['id' => '686670374445-mhktaj9gp08p6oiu8e1aue3ckua6e3s3.apps.googleusercontent.com', 'secret' => '4yOeNxYuYE4H8DFhVzQlOb_U'],
20 20
         ],
21 21
 
22 22
         'Facebook' => [
23 23
             'enabled' => true,
24
-            'keys' => ['id' => '', 'secret' => ''],
24
+            'keys' => ['id' => '432266300978748', 'secret' => '43815184db62771fce19b64cdd80110a'],
25 25
         ],
26 26
 
27 27
         'Twitter' => [
28 28
             'enabled' => true,
29
-            'keys' => ['key' => '', 'secret' => ''],
29
+            'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'],
30 30
         ]
31 31
     ],
32 32
     //optional : set debug mode
33 33
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<?php
2
+define("APPLICATION_PATH", dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "application");
3
+define("MODULES_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules");
4
+define("CONTROLLERS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
5
+define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config");
6
+define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs");
7
+define("MODELS_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles");
8
+define("VIEW_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues");
9
+define("CONTROLLER_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs");
10
+define("TRAITEMENT_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements");
0 11
\ No newline at end of file
... ...
@@ -1,5 +1,7 @@
1 1
 <?php
2
-\MVC\Session::isregistered();
2
+
3
+\MVC\Classe\Session::start();
4
+//\MVC\Classe\Session::isregistered();
3 5
 
4 6
 require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
5 7
 
... ...
@@ -8,11 +10,12 @@ $adapters = $hybridauth->getConnectedAdapters();
8 10
 
9 11
 $templateData['adapters'] = $adapters;
10 12
 
11
-$templateData['extractedData'] = [
13
+/*$templateData['extractedData'] = [
12 14
     'token' => $_SESSION['userToken'],
13 15
     'identifier' => $_SESSION['userProfile']->identifier,
14 16
     'email' => $_SESSION['userProfile']->email,
15 17
     'first_name' => $_SESSION['userProfile']->firstName,
16 18
     'last_name' => $_SESSION['userProfile']->lastName,
17 19
     'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'),
18
-];
20
+];*/
21
+$templateData['extractedData'] = [];
... ...
@@ -7,17 +7,17 @@
7 7
     @section('top-css')
8 8
     @endsection
9 9
 
10
-    @section('top-javascript')
11
-    @endsection
12
-
13 10
 </head>
14 11
 
15 12
 <body>
16 13
 
14
+@section('top-javascript')
15
+@show
16
+
17 17
 @yield('body')
18 18
 
19 19
 @section('bottom-javascript')
20
-@endsection
20
+@show
21 21
 
22 22
 </body>
23 23
 
... ...
@@ -9,6 +9,8 @@
9 9
 @section('content')
10 10
     <h1>Accueil</h1>
11 11
     <br /><br /><br />
12
+    <a href="{{ \MVC\Classe\Url::link_rewrite(false, 'authentification', []) }}">S'authentifier ?</a>
13
+    <hr/>
12 14
     {{$templating_a}}::{{$templating_b}}::{{$templating_c}}
13 15
 
14 16
 @endsection
... ...
@@ -19,15 +19,16 @@
19 19
                 </li>
20 20
             @endif
21 21
         @endforeach
22
-        <ul>
23
-            @endsection
22
+    </ul>
23
+@endsection
24 24
 
25
-            @section('top-javascript')
26
-                <script>
27
-                    function auth_popup(provider) {
28
-                        // replace 'path/to/hybridauth' with the real path to this script
29
-                        var authWindow = window.open('/control/authentification-callback-example/provider/' + provider, 'authWindow', 'width=600,height=400,scrollbars=yes');
30
-                        return false;
31
-                    }
32
-                </script>
25
+@section('top-javascript')
26
+    <script>
27
+        function auth_popup(provider) {
28
+            // replace 'path/to/hybridauth' with the real path to this script
29
+            var authWindow = window.open('{{ \MVC\Classe\Url::link_rewrite(true, 'authentification-callback-example', []) }}/provider/' + provider, 'authWindow', 'width=600,height=400,scrollbars=yes');
30
+            return false;
31
+        }
32
+    </script>
33 33
 @endsection
34
+
... ...
@@ -21,7 +21,8 @@
21 21
                 <li>
22 22
                     <strong>{{$adapter->getUserProfile()->displayName }}</strong> from
23 23
                     <i>{{ $name }}</i>
24
-                    <span>(<a href="{{$config['callback'] }}?logout={{ $name }}" ; ?>">Log Out</a>)</span>
24
+                    <span>(<a href="{{ \MVC\Classe\Url::link_rewrite( true, 'authentification-callback-example', ['logout'=>$name ]) }}"
25
+                              ; ?>">Log Out</a>)</span>
25 26
                 </li>
26 27
             @endforeach
27 28
         </ul>
... ...
@@ -3,7 +3,7 @@
3 3
  * A simple example that shows how to use multiple providers, opening provider authentication in a pop-up.
4 4
  */
5 5
 
6
-use Hybridauth\Hybridauth;
6
+use MVC\Classe\Dumper;
7 7
 
8 8
 require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
9 9
 
... ...
@@ -20,9 +20,9 @@ try {
20 20
         // Validate provider exists in the $config
21 21
         if (in_array($url_params['provider'], $hybridauth->getProviders())) {
22 22
             // Store the provider for the callback event
23
-            $storage->set('provider', $_GET['provider']);
23
+            $storage->set('provider', $url_params['provider']);
24 24
         } else {
25
-            $error = $_GET['provider'];
25
+            $error = $url_params['provider'];
26 26
         }
27 27
     }
28 28
 
... ...
@@ -42,7 +42,7 @@ try {
42 42
     //
43 43
     // Handle invalid provider errors
44 44
     //
45
-    if ($error) {
45
+    if ($error !== false) {
46 46
         error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config');
47 47
         // Close the pop-up window
48 48
         echo "
... ...
@@ -56,22 +56,32 @@ try {
56 56
     //
57 57
     // Event 3: Provider returns via CALLBACK
58 58
     //
59
-    if ($provider = $storage->get('provider')) {
59
+    if ($url_params['provider'] = $storage->get('provider')) {
60 60
 
61
-        $hybridauth->authenticate($provider);
61
+        $hybridauth->authenticate($url_params['provider']);
62
+
63
+        die('OK!');
62 64
         $storage->set('provider', null);
63 65
 
64 66
         // Retrieve the provider record
65
-        $adapter = $hybridauth->getAdapter($provider);
66
-        $userProfile = $adapter->getUserProfile();
67
-        $accessToken = $adapter->getAccessToken();
67
+        $adapter = $hybridauth->getAdapter($url_params['provider']);
68
+
69
+        Dumper::dump($adapter->getUserProfile());
70
+        Dumper::dump($adapter->getAccessToken());
71
+
72
+
73
+        \MVC\Classe\Session::start();
74
+        \MVC\Classe\Session::setUserProfile($adapter->getUserProfile());
75
+        \MVC\Classe\Session::setToken($adapter->getAccessToken());
68 76
 
69 77
         // Close pop-up window
70
-        echo "
78
+        echo <<<EOD
79
+
71 80
             <script>
72
-                window.opener.location.reload();
73
-                window.close();
74
-            </script>";
81
+                window.opener.location.assign('compte');
82
+                self.close();
83
+            </script>
84
+EOD;
75 85
 
76 86
     }
77 87
 
... ...
@@ -1,5 +1,9 @@
1 1
 {
2 2
     "autoload": {
3
+      "files": [
4
+        "./application/config/define-constantes.php"
5
+      ],
6
+
3 7
         "psr-4": {
4 8
             "MVC\\Classe\\":"./application/class",
5 9
             "MVC\\Objets\\":"./application/objets"
... ...
@@ -3,10 +3,8 @@
3 3
 error_reporting(-1);
4 4
 ini_set('display_errors', 1);
5 5
 
6
-define("APPLICATION_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."application");
7
-define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor");
8
-define("MODULES_PATH", APPLICATION_PATH.DIRECTORY_SEPARATOR."modules");
9 6
 
7
+define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor");
10 8
 require VENDOR_PATH.DIRECTORY_SEPARATOR."autoload.php";
11 9
 
12 10
 $poo_v5 = new \MVC\Classe\Application();