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) +}