@modelcontextprotocol/sdk
    Preparing search index...

    Function exchangeAuthorization

    • Exchanges an authorization code for an access token with the given server.

      Supports multiple client authentication methods as specified in OAuth 2.1:

      • Automatically selects the best authentication method based on server support
      • Falls back to appropriate defaults when server metadata is unavailable

      Parameters

      • authorizationServerUrl: string | URL

        The authorization server's base URL

      • options: {
            addClientAuthentication?: (
                headers: Headers,
                params: URLSearchParams,
                url: string | URL,
                metadata?: AuthorizationServerMetadata,
            ) => void | Promise<void>;
            authorizationCode: string;
            clientInformation: OAuthClientInformationMixed;
            codeVerifier: string;
            fetchFn?: FetchLike;
            metadata?: AuthorizationServerMetadata;
            redirectUri: string | URL;
            resource?: URL;
        }

        Configuration object containing client info, auth code, etc.

      Returns Promise<
          {
              access_token: string;
              expires_in?: number;
              id_token?: string;
              refresh_token?: string;
              scope?: string;
              token_type: string;
          },
      >

      Promise resolving to OAuth tokens

      When token exchange fails or authentication is invalid