Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/client/src/client/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,25 @@ export async function handleOAuthUnauthorized(provider: OAuthClientProvider, ctx
* original `OAuthClientProvider` for OAuth-specific paths (`finishAuth()`, 403 upscoping).
*/
export function adaptOAuthProvider(provider: OAuthClientProvider): AuthProvider {
let inflightRefresh: Promise<void> | undefined;
return {
token: async () => {
const tokens = await provider.tokens();
return tokens?.access_token;
},
onUnauthorized: async ctx => handleOAuthUnauthorized(provider, ctx)
onUnauthorized: async ctx => {
// Deduplicate concurrent 401 handlers to prevent multiple
// refresh token exchanges. OAuth providers with rotating
// refresh tokens (RFC 6819 5.2.2.3) revoke the entire
// token family when a refresh token is used more than once.
if (inflightRefresh) {
return inflightRefresh;
}
inflightRefresh = handleOAuthUnauthorized(provider, ctx).finally(() => {
inflightRefresh = undefined;
});
return inflightRefresh;
}
};
}

Expand Down
Loading