(
issuer: string | URL,
{
authorizationServerUrl,
protocolVersion
}: {
authorizationServerUrl?: string | URL;
protocolVersion?: string;
} = {},
fetchFn: FetchLike = fetch
)
| 864 | * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`. |
| 865 | */ |
| 866 | export async function discoverOAuthMetadata( |
| 867 | issuer: string | URL, |
| 868 | { |
| 869 | authorizationServerUrl, |
| 870 | protocolVersion |
| 871 | }: { |
| 872 | authorizationServerUrl?: string | URL; |
| 873 | protocolVersion?: string; |
| 874 | } = {}, |
| 875 | fetchFn: FetchLike = fetch |
| 876 | ): Promise<OAuthMetadata | undefined> { |
| 877 | if (typeof issuer === 'string') { |
| 878 | issuer = new URL(issuer); |
| 879 | } |
| 880 | if (!authorizationServerUrl) { |
| 881 | authorizationServerUrl = issuer; |
| 882 | } |
| 883 | if (typeof authorizationServerUrl === 'string') { |
| 884 | authorizationServerUrl = new URL(authorizationServerUrl); |
| 885 | } |
| 886 | protocolVersion ??= LATEST_PROTOCOL_VERSION; |
| 887 | |
| 888 | const response = await discoverMetadataWithFallback(authorizationServerUrl, 'oauth-authorization-server', fetchFn, { |
| 889 | protocolVersion, |
| 890 | metadataServerUrl: authorizationServerUrl |
| 891 | }); |
| 892 | |
| 893 | if (!response || response.status === 404) { |
| 894 | await response?.body?.cancel(); |
| 895 | return undefined; |
| 896 | } |
| 897 | |
| 898 | if (!response.ok) { |
| 899 | await response.body?.cancel(); |
| 900 | throw new Error(`HTTP ${response.status} trying to load well-known OAuth metadata`); |
| 901 | } |
| 902 | |
| 903 | return OAuthMetadataSchema.parse(await response.json()); |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Builds a list of discovery URLs to try for authorization server metadata. |
no test coverage detected
searching dependent graphs…