Skip to content

fix: Add setupAutoRefresh in oauth-client

Paul Slaughter requested to merge ps-refresh-token-in-auth-provider into main

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,
 });

  1. Apply this patch to set token lifetime to 6 minutes
  2. Run yarn start:example
  3. Open Chrome at localhost:8000 and set Web IDE config to point to local GDK with OAuth
  4. Open the Web IDE logs with command GitLab Web IDE: Show logs
  5. Wait 2 minutes for the log GitLabAuthenticationProvider - New token received. Updating token.

Screenshot

Screenshot_2024-02-29_at_4.46.24_PM

  • 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
Screenshot_2024-02-29_at_4.46.33_PM Screenshot_2024-02-29_at_4.47.05_PM
Edited by Paul Slaughter

Merge request reports