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

Ajout intégration de l'hybridAuthentification encore en état de code brut Pas de tests

TODO: aller chercher les token et les id des authentifcation pour google, github, facebook, twitter ... Reste a tester et à décider pour les autres types d'authentification.

Emmanuel ROY authored on 26/09/2019 04:27:05
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php";
4
+
5
+try {
6
+    //Feed configuration array to Hybridauth
7
+    $hybridauth = new \Hybridauth\Hybridauth($config);
8
+
9
+    //Then we can proceed and sign in with Twitter as an example. If you want to use a diffirent provider,
10
+    //simply replace 'Twitter' with 'Google' or 'Facebook'.
11
+
12
+    //Attempt to authenticate users with a Twitter provider
13
+    $adapter = $hybridauth->authenticate('Twitter');
14
+    //Returns a boolean of whether the user is connected with Twitter
15
+    $isConnected = $adapter->isConnected();
16
+
17
+    if ($isConnected == false) {
18
+        //Attempt to authenticate users with a Google provider
19
+        $adapter = $hybridauth->authenticate('Google');
20
+        $isConnected = $adapter->isConnected();
21
+    }
22
+    if ($isConnected == false) {
23
+        //Attempt to authenticate users with a Facebook provider
24
+        $adapter = $hybridauth->authenticate('Facebook');
25
+        $isConnected = $adapter->isConnected();
26
+    }
27
+    if ($isConnected == false) {
28
+        //Attempt to authenticate users with a Github provider
29
+        $adapter = $hybridauth->authenticate('Github');
30
+        $isConnected = $adapter->isConnected();
31
+    }
32
+
33
+
34
+    if ($isConnected) {
35
+        session_start();
36
+        //Retrieve the user's token
37
+        $token = $adapter->getAccessToken();
38
+        $_SESSION['accessToken'] = $token;
39
+
40
+        //Retrieve the user's profile
41
+        $userProfile = $adapter->getUserProfile();
42
+        $_SESSION['userProfile'] = $userProfile;
43
+
44
+        //Disconnect the adapter
45
+        $adapter->disconnect();
46
+
47
+        header("location:" . Url::link_rewrite(false, 'compte', []));
48
+
49
+    } else {
50
+
51
+        header("location:" . Url::link_rewrite(false, 'error', []));
52
+
53
+    }
54
+
55
+} catch (\Exception $e) {
56
+    echo 'Oops, we ran into an issue! ' . $e->getMessage();
57
+}
0 58
\ No newline at end of file