( serverUrl: string, resourceMetadata?: OAuthProtectedResourceMetadata, fetchFn?: typeof fetch, )
| 20 | * @returns Promise resolving to space-separated scope string or undefined |
| 21 | */ |
| 22 | export const discoverScopes = async ( |
| 23 | serverUrl: string, |
| 24 | resourceMetadata?: OAuthProtectedResourceMetadata, |
| 25 | fetchFn?: typeof fetch, |
| 26 | ): Promise<string | undefined> => { |
| 27 | try { |
| 28 | const metadata = await discoverAuthorizationServerMetadata( |
| 29 | new URL("/", serverUrl), |
| 30 | { fetchFn }, |
| 31 | ); |
| 32 | |
| 33 | // Prefer resource metadata scopes, but fall back to OAuth metadata if empty |
| 34 | const resourceScopes = resourceMetadata?.scopes_supported; |
| 35 | const oauthScopes = metadata?.scopes_supported; |
| 36 | |
| 37 | const scopesSupported = |
| 38 | resourceScopes && resourceScopes.length > 0 |
| 39 | ? resourceScopes |
| 40 | : oauthScopes; |
| 41 | |
| 42 | return scopesSupported && scopesSupported.length > 0 |
| 43 | ? scopesSupported.join(" ") |
| 44 | : undefined; |
| 45 | } catch (error) { |
| 46 | console.debug("OAuth scope discovery failed:", error); |
| 47 | return undefined; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | export const getClientInformationFromSessionStorage = async ({ |
| 52 | serverUrl, |
no outgoing calls
no test coverage detected