@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: {
                client_id: string;
                client_id_issued_at?: number;
                client_secret?: string;
                client_secret_expires_at?: number;
            };
            codeVerifier: string;
            fetchFn?: FetchLike;
            metadata?: AuthorizationServerMetadata;
            redirectUri: string
            | URL;
            resource?: URL;
        }

        Configuration object containing client info, auth code, etc.

        • OptionaladdClientAuthentication?: (
              headers: Headers,
              params: URLSearchParams,
              url: string | URL,
              metadata?: AuthorizationServerMetadata,
          ) => void | Promise<void>
        • authorizationCode: string
        • clientInformation: {
              client_id: string;
              client_id_issued_at?: number;
              client_secret?: string;
              client_secret_expires_at?: number;
          }
        • codeVerifier: string
        • OptionalfetchFn?: FetchLike
        • Optionalmetadata?: AuthorizationServerMetadata
        • redirectUri: string | URL
        • Optionalresource?: URL

      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