Skip to content

Commit 3470d3b

Browse files
committed
persist refresk token in a session
1 parent f9a15e0 commit 3470d3b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

analyticsdata/quickstart_oauth2/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Choose "Web application" when asked for an application type.
1414
https://support.google.com/cloud/answer/6158849
1515

1616
2. When configuring the web application credentials, add
17-
"http://localhost:3000" to "Authorized redirect URIs".
17+
"http://localhost:3000/" to "Authorized redirect URIs".
1818

1919
3. Download a credentials file using "Download JSON" button in the credentials
2020
configuration dialog and save it as `oauth2.keys.json` in the same
@@ -38,4 +38,4 @@ php -S localhost:3000 -t .
3838
```
3939
7. In a browser, open the following url to start the sample:
4040

41-
https://localhost:3000/
41+
http://localhost:3000/

analyticsdata/quickstart_oauth2/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
5151
// This is the final step of the OAuth2 authorization process, where an
5252
// OAuth2 access token is available and can be used to set up a client.
53-
$oauth->updateToken(['refresh_token' => $_SESSION['access_token']]);
53+
$oauth->setAccessToken($_SESSION['access_token']);
54+
$oauth->setRefreshToken($_SESSION['refresh_token']);
5455

5556
// Make an API call.
5657
$client = new AlphaAnalyticsDataClient(['credentials' => $oauth]);
@@ -98,6 +99,9 @@
9899
// Persist the acquired access token in a session.
99100
$_SESSION['access_token'] = $oauth->getAccessToken();
100101

102+
// Persist the acquired refresh token in a session.
103+
$_SESSION['refresh_token'] = $oauth->getRefreshToken();
104+
101105
// Refresh the current page.
102106
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
103107
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));

0 commit comments

Comments
 (0)