* Safely extracts scope information from AuthorizationServerMetadata. * The metadata can be either OAuthMetadata or OpenIdProviderDiscoveryMetadata, * and different providers use different fields for scope information.
( metadata: AuthorizationServerMetadata | undefined, )
| 2443 | * and different providers use different fields for scope information. |
| 2444 | */ |
| 2445 | function getScopeFromMetadata( |
| 2446 | metadata: AuthorizationServerMetadata | undefined, |
| 2447 | ): string | undefined { |
| 2448 | if (!metadata) return undefined |
| 2449 | // Try 'scope' first (non-standard but used by some providers) |
| 2450 | if ('scope' in metadata && typeof metadata.scope === 'string') { |
| 2451 | return metadata.scope |
| 2452 | } |
| 2453 | // Try 'default_scope' (non-standard but used by some providers) |
| 2454 | if ( |
| 2455 | 'default_scope' in metadata && |
| 2456 | typeof metadata.default_scope === 'string' |
| 2457 | ) { |
| 2458 | return metadata.default_scope |
| 2459 | } |
| 2460 | // Fall back to scopes_supported (standard OAuth 2.0 field) |
| 2461 | if (metadata.scopes_supported && Array.isArray(metadata.scopes_supported)) { |
| 2462 | return metadata.scopes_supported.join(' ') |
| 2463 | } |
| 2464 | return undefined |
| 2465 | } |
| 2466 |
no outgoing calls
no test coverage detected