MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / discoverOAuthMetadata

Function discoverOAuthMetadata

src/client/auth.ts:866–904  ·  view source on GitHub ↗
(
    issuer: string | URL,
    {
        authorizationServerUrl,
        protocolVersion
    }: {
        authorizationServerUrl?: string | URL;
        protocolVersion?: string;
    } = {},
    fetchFn: FetchLike = fetch
)

Source from the content-addressed store, hash-verified

864 * @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`.
865 */
866export 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.

Callers 1

auth.test.tsFile · 0.85

Calls 2

parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…