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
This commit is contained in:
Xiao Yijun 2025-05-15 01:45:18 +08:00 • committed by GitHub
commit 66dec56467
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,7 +84,14 @@ export class UnauthorizedError extends Error {
*/
export async function auth(
provider: OAuthClientProvider,
{ serverUrl, authorizationCode }: { serverUrl: string | URL, authorizationCode?: string }): Promise<AuthResult> {
{ serverUrl,
authorizationCode,
scope,
}: {
serverUrl: string | URL;
authorizationCode?: string;
scope?: string;
}): Promise<AuthResult> {
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);