MCPcopy Index your code
hub / github.com/modelcontextprotocol/typescript-sdk / auth

Function auth

src/client/auth.ts:401–426  ·  view source on GitHub ↗
(
    provider: OAuthClientProvider,
    options: {
        serverUrl: string | URL;
        authorizationCode?: string;
        scope?: string;
        resourceMetadataUrl?: URL;
        fetchFn?: FetchLike;
    }
)

Source from the content-addressed store, hash-verified

399 * instead of linking together the other lower-level functions in this module.
400 */
401export async function auth(
402 provider: OAuthClientProvider,
403 options: {
404 serverUrl: string | URL;
405 authorizationCode?: string;
406 scope?: string;
407 resourceMetadataUrl?: URL;
408 fetchFn?: FetchLike;
409 }
410): Promise<AuthResult> {
411 try {
412 return await authInternal(provider, options);
413 } catch (error) {
414 // Handle recoverable error types by invalidating credentials and retrying
415 if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
416 await provider.invalidateCredentials?.('all');
417 return await authInternal(provider, options);
418 } else if (error instanceof InvalidGrantError) {
419 await provider.invalidateCredentials?.('tokens');
420 return await authInternal(provider, options);
421 }
422
423 // Throw otherwise
424 throw error;
425 }
426}
427
428async function authInternal(
429 provider: OAuthClientProvider,

Callers 10

auth.test.tsFile · 0.85
handle401Function · 0.85
_authThenStartMethod · 0.85
finishAuthMethod · 0.85
sendMethod · 0.85
withOAuthFunction · 0.85
_authThenStartMethod · 0.85
finishAuthMethod · 0.85
sendMethod · 0.85

Calls 2

authInternalFunction · 0.85
invalidateCredentialsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…