fix: Add setupAutoRefresh in oauth-client
- Part 3: feat: Update vscode extension to use auth provider (!288 - merged)
- Related MR's:
Description
In the initial implementation of our GitLabAuthenticationProvider
we didn't expose or keep track of expiresAt
once in the extension sandbox, so if the Web IDE is inactive we won't ever refresh. Let's create a helpful setupAutoRefresh
in the oauth-client
to encapsulate this.
How to test
diff --git a/packages/example/src/components/WebIde.vue b/packages/example/src/components/WebIde.vue
index 0b7b72f..404c7e4 100644
--- a/packages/example/src/components/WebIde.vue
+++ b/packages/example/src/components/WebIde.vue
@@ -33,6 +33,7 @@ const getAuthConfigFromExample = ({
callbackUrl: getOAuthCallbackUrl(),
// why: Let's use regular refreshToken since we can't silently reauth in the example app
protectRefreshToken: false,
+ tokenLifetime: 360,
};
}
diff --git a/packages/example/src/oauth_callback.ts b/packages/example/src/oauth_callback.ts
index 489d8c5..762f6eb 100644
--- a/packages/example/src/oauth_callback.ts
+++ b/packages/example/src/oauth_callback.ts
@@ -26,6 +26,7 @@ oauthCallback({
clientId: config.clientId,
// why: Let's use regular refreshToken since we can't silently reauth in the example app
protectRefreshToken: false,
+ tokenLifetime: 360,
},
username: url.searchParams.get('username') || undefined,
});
- Apply this patch to set token lifetime to 6 minutes
☝ - Run
yarn start:example
- Open Chrome at
localhost:8000
and set Web IDE config to point to local GDK with OAuth - Open the Web IDE logs with command
GitLab Web IDE: Show logs
- Wait 2 minutes for the log
GitLabAuthenticationProvider - New token received. Updating token.
Screenshot
- From 22:40:42 to 22:42:00 and 22:42:00 to 22:43:59 the token was refreshed by opening a file which triggers a
getToken
that will automatically refresh if needed.
Last token in storage | Token used in GitLab Workflow Extension |
---|---|
![]() |
![]() |
Edited by Paul Slaughter