(
provider: OAuthClientProvider,
options: {
serverUrl: string | URL;
authorizationCode?: string;
scope?: string;
resourceMetadataUrl?: URL;
fetchFn?: FetchLike;
}
)
| 399 | * instead of linking together the other lower-level functions in this module. |
| 400 | */ |
| 401 | export 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 | |
| 428 | async function authInternal( |
| 429 | provider: OAuthClientProvider, |
no test coverage detected
searching dependent graphs…