-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
refresh_token.diff
44 lines (40 loc) · 1.74 KB
/
refresh_token.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
diff --git a/examples/oauth.ts b/examples/refresh_token.ts
index d55e62d..0abcb8a 100644
--- a/examples/oauth.ts
+++ b/examples/refresh_token.ts
@@ -41,7 +41,7 @@ let state: string | undefined
authorizationUrl.searchParams.set('client_id', client.client_id)
authorizationUrl.searchParams.set('redirect_uri', redirect_uri)
authorizationUrl.searchParams.set('response_type', 'code')
- authorizationUrl.searchParams.set('scope', 'api:read')
+ authorizationUrl.searchParams.set('scope', 'api:read offline_access')
authorizationUrl.searchParams.set('code_challenge', code_challenge)
authorizationUrl.searchParams.set('code_challenge_method', code_challenge_method)
@@ -60,6 +60,7 @@ let state: string | undefined
// one eternity later, the user lands back on the redirect_uri
// Authorization Code Grant Request & Response
let access_token: string
+let refresh_token: string | undefined
{
const currentUrl: URL = getCurrentUrl()
const params = oauth.validateAuthResponse(as, client, currentUrl, state)
@@ -76,7 +77,7 @@ let access_token: string
const result = await oauth.processAuthorizationCodeResponse(as, client, response)
console.log('Access Token Response', result)
- ;({ access_token } = result)
+ ;({ access_token, refresh_token } = result)
}
// Protected Resource Request
@@ -89,3 +90,13 @@ let access_token: string
console.log('Protected Resource Response', await response.json())
}
+
+// Refresh Token Grant Request & Response
+if (refresh_token) {
+ const response = await oauth.refreshTokenGrantRequest(as, client, clientAuth, refresh_token)
+
+ const result = await oauth.processRefreshTokenResponse(as, client, response)
+
+ console.log('Access Token Response', result)
+ ;({ access_token, refresh_token } = result)
+}