From 66dec56467b8f562b2c8cec8c2b41f97dd819777 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Thu, 15 May 2025 01:45:18 +0800 Subject: [PATCH] feat(auth): support custom scope in authorization requests (#491) * feat(auth): support custom scope in authorization requests * fix(auth): default to provider's scope if not provided --- src/client/auth.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/auth.ts b/src/client/auth.ts index b170cefc..e4941576 100644 --- a/src/client/auth.ts +++ b/src/client/auth.ts @@ -84,7 +84,14 @@ export class UnauthorizedError extends Error { */ export async function auth( provider: OAuthClientProvider, - { serverUrl, authorizationCode }: { serverUrl: string | URL, authorizationCode?: string }): Promise { + { serverUrl, + authorizationCode, + scope, + }: { + serverUrl: string | URL; + authorizationCode?: string; + scope?: string; + }): Promise { const metadata = await discoverOAuthMetadata(serverUrl); // Handle client registration if needed @@ -146,7 +153,7 @@ export async function auth( metadata, clientInformation, redirectUrl: provider.redirectUrl, - scope: provider.clientMetadata.scope + scope: scope || provider.clientMetadata.scope, }); await provider.saveCodeVerifier(codeVerifier);