@@ -80,13 +80,16 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
8080 const metadata = context . state . oauthMetadata ! ;
8181 const clientMetadata = context . provider . clientMetadata ;
8282
83- // Prefer scopes from resource metadata if available
84- const scopesSupported =
85- context . state . resourceMetadata ?. scopes_supported ||
86- metadata . scopes_supported ;
87- // Add all supported scopes to client registration
88- if ( scopesSupported ) {
89- clientMetadata . scope = scopesSupported . join ( " " ) ;
83+ // Priority: user-provided scope > discovered scopes
84+ if ( ! context . provider . scope || context . provider . scope . trim ( ) === "" ) {
85+ // Prefer scopes from resource metadata if available
86+ const scopesSupported =
87+ context . state . resourceMetadata ?. scopes_supported ||
88+ metadata . scopes_supported ;
89+ // Add all supported scopes to client registration
90+ if ( scopesSupported ) {
91+ clientMetadata . scope = scopesSupported . join ( " " ) ;
92+ }
9093 }
9194
9295 // Try Static client first, with DCR as fallback
@@ -113,10 +116,14 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = {
113116 const metadata = context . state . oauthMetadata ! ;
114117 const clientInformation = context . state . oauthClientInfo ! ;
115118
116- const scope = await discoverScopes (
117- context . serverUrl ,
118- context . state . resourceMetadata ?? undefined ,
119- ) ;
119+ // Priority: user-provided scope > discovered scopes
120+ let scope = context . provider . scope ;
121+ if ( ! scope || scope . trim ( ) === "" ) {
122+ scope = await discoverScopes (
123+ context . serverUrl ,
124+ context . state . resourceMetadata ?? undefined ,
125+ ) ;
126+ }
120127
121128 const { authorizationUrl, codeVerifier } = await startAuthorization (
122129 context . serverUrl ,
0 commit comments