( input: RefreshAccessTokenInput, )
| 641 | }; |
| 642 | |
| 643 | export const refreshAccessToken = ( |
| 644 | input: RefreshAccessTokenInput, |
| 645 | ): Effect.Effect<OAuth2TokenResponse, OAuth2Error> => |
| 646 | Effect.tryPromise({ |
| 647 | try: async () => { |
| 648 | const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, { |
| 649 | idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported, |
| 650 | endpointUrlPolicy: input.endpointUrlPolicy, |
| 651 | }); |
| 652 | const client: oauth.Client = { client_id: input.clientId }; |
| 653 | const clientAuth = pickClientAuth( |
| 654 | input.clientSecret, |
| 655 | input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD, |
| 656 | ); |
| 657 | const extraParams = new URLSearchParams(); |
| 658 | if (input.scopes && input.scopes.length > 0) { |
| 659 | extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " ")); |
| 660 | } |
| 661 | if (input.resource) { |
| 662 | extraParams.set("resource", input.resource); |
| 663 | } |
| 664 | const additionalParameters = |
| 665 | Array.from(extraParams.keys()).length > 0 ? extraParams : undefined; |
| 666 | const response = await oauth.refreshTokenGrantRequest( |
| 667 | as, |
| 668 | client, |
| 669 | clientAuth, |
| 670 | input.refreshToken, |
| 671 | { |
| 672 | ...oauth4webapiRequestOptions( |
| 673 | input.tokenUrl, |
| 674 | input.timeoutMs, |
| 675 | input.endpointUrlPolicy, |
| 676 | input.fetch, |
| 677 | ), |
| 678 | additionalParameters, |
| 679 | }, |
| 680 | ); |
| 681 | const result = await oauth.processRefreshTokenResponse( |
| 682 | as, |
| 683 | client, |
| 684 | await stripIdToken(response), |
| 685 | ); |
| 686 | return tokenResponseFrom(result); |
| 687 | }, |
| 688 | catch: (cause) => cause, |
| 689 | }).pipe(Effect.catch(failOAuth2WithHttpSummary)); |
| 690 | |
| 691 | // --------------------------------------------------------------------------- |
| 692 | // Refresh-needed predicate |
no test coverage detected