You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2- Edit the callback page to create an instance of the `Auth0` class in order to exchange the authorization code (provided by Auth0) for an access_token:
21
+
In there, you should create an instance of the SDK with the proper configuration and ask for the user information.
34
22
35
23
~~~php
36
24
use Auth0SDK\Auth0;
@@ -39,19 +27,69 @@ $auth0 = new Auth0(array(
39
27
'domain' => 'YOUR_AUTH0_DOMAIN',
40
28
'client_id' => 'YOUR_AUTH0_CLIENT_ID',
41
29
'client_secret' => 'YOUR_AUTH0_CLIENT_SECRET',
42
-
'redirect_uri' => 'YOUR_AUTH0_APP_CALLBACK',
43
-
'debug' => true
30
+
'redirect_uri' => 'http://<name>/callback.php'
44
31
));
45
32
46
-
$access_token = $auth0->getAccessToken();
33
+
$userInfo = $auth0->getUserInfo();
47
34
~~~
48
35
49
-
3- Once the user successfully authenticated to the application, you can retrieve his profile:
36
+
If the user was already logged in, `getUserInfo()` will retrieve that [user information](https://docs.auth0.com/user-profile) from the `PHP Session`. If not, it will try to exchange the code given to the callback to get an access token, id token and the [user information](https://docs.auth0.com/user-profile) from auth0.
37
+
38
+
This makes it possible to use the same code in the callback action and any other page, so to see if there is a logged in user, you can call
39
+
50
40
51
41
~~~php
52
-
$userProfile = $auth0->getUserInfo();
42
+
// ...
43
+
// code from above
44
+
45
+
if (!$userInfo) {
46
+
// print login button
47
+
} else {
48
+
// Say hello to $userInfo['name']
49
+
// print logout button
50
+
}
53
51
~~~
54
52
53
+
### 3. Setup the callback action in Auth0
54
+
55
+
After authenticating the user on Auth0, we will do a GET to a URL on your web site. For security purposes, you have to register this URL on the Application Settings section on Auth0 Admin app.
56
+
57
+
http://<name>/callback.php
58
+
59
+
60
+
### 4. Triggering login manually or integrating the Auth0 widget
61
+
62
+
You can trigger the login in different ways, like redirecting to a login link or using the [Login Widget](https://docs.auth0.com/login-widget2), by adding the following javascript into your page
By default, the SDK will store the [user information](https://docs.auth0.com/user-profile) in the `PHP Session` and it will discard the access token and the id token. If you like to persist them as well, you can pass `persist_access_token => true` and `persist_id_token => true` to the SDK configuration in step 2. You can also disable session all together by passing `store => false`.
80
+
81
+
If you want to change `PHP Session` and use Laravel, Zend, Symfony or other abstraction to the session, you can create a class that implements `get`, `set`, `delete` and pass it to the SDK as following.
82
+
83
+
~~~php
84
+
$laravelStore = new MyLaravelStore();
85
+
$auth0 = new Auth0(array(
86
+
// ...
87
+
'store' => $laravelStore,
88
+
// ...
89
+
));
90
+
~~~
91
+
92
+
55
93
## Develop
56
94
57
95
This SDK uses [Composer](http://getcomposer.org/doc/01-basic-usage.md) to manage its dependencies.
0 commit comments