|
30 | 30 | unset($_SESSION['oauth2state']); |
31 | 31 | exit('Invalid state'); |
32 | 32 | } |
33 | | -else { |
34 | | - |
35 | | - // Try to get an access token (using the authorization code grant) |
36 | | - $token = $provider->getAccessToken('authorization_code', |
37 | | - [ |
38 | | - 'code' => $_GET['code'] |
39 | | - ]); |
40 | | - |
41 | | - // Optional: Now you have a token you can look up a users profile data |
42 | | - try { |
43 | | - // We got an access token, let's now get the owner details |
44 | | - $ownerDetails = $provider->getResourceOwner($token); |
45 | | - |
46 | | - // Use these details to create a new profile |
47 | | - printf('Hello %s!', $ownerDetails->getFirstName()); |
48 | | - } catch (Exception $e) { |
49 | | - |
50 | | - // Failed to get user details |
51 | | - exit('Something went wrong: ' . $e->getMessage()); |
52 | | - } |
53 | | - |
54 | | - // Use this to interact with an API on the users behalf |
55 | | - echo $token->getToken(); |
| 33 | +// Try to get an access token (using the authorization code grant) |
| 34 | +$token = $provider->getAccessToken('authorization_code', |
| 35 | + [ |
| 36 | + 'code' => $_GET['code'] |
| 37 | + ]); |
| 38 | +// Optional: Now you have a token you can look up a users profile data |
| 39 | +try { |
| 40 | + // We got an access token, let's now get the owner details |
| 41 | + $ownerDetails = $provider->getResourceOwner($token); |
56 | 42 |
|
57 | | - // Use this to get a new access token if the old one expires |
58 | | - echo $token->getRefreshToken(); |
| 43 | + // Use these details to create a new profile |
| 44 | + printf('Hello %s!', $ownerDetails->getFirstName()); |
| 45 | +} catch (Exception $e) { |
59 | 46 |
|
60 | | - // Unix timestamp at which the access token expires |
61 | | - echo $token->getExpires(); |
| 47 | + // Failed to get user details |
| 48 | + exit('Something went wrong: ' . $e->getMessage()); |
62 | 49 | } |
| 50 | +// Use this to interact with an API on the users behalf |
| 51 | +echo $token->getToken(); |
| 52 | +// Use this to get a new access token if the old one expires |
| 53 | +echo $token->getRefreshToken(); |
| 54 | +// Unix timestamp at which the access token expires |
| 55 | +echo $token->getExpires(); |
0 commit comments