( input: RefreshAccessTokenInput, )
| 695 | }; |
| 696 | |
| 697 | export const refreshAccessToken = ( |
| 698 | input: RefreshAccessTokenInput, |
| 699 | ): Effect.Effect<OAuth2TokenResponse, OAuth2Error> => |
| 700 | Effect.tryPromise({ |
| 701 | try: async () => { |
| 702 | const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, { |
| 703 | idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported, |
| 704 | endpointUrlPolicy: input.endpointUrlPolicy, |
| 705 | }); |
| 706 | const client: oauth.Client = { client_id: input.clientId }; |
| 707 | const clientAuth = pickClientAuth( |
| 708 | input.clientSecret, |
| 709 | input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD, |
| 710 | ); |
| 711 | const extraParams = new URLSearchParams(); |
| 712 | if (input.scopes && input.scopes.length > 0) { |
| 713 | extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " ")); |
| 714 | } |
| 715 | if (input.resource) { |
| 716 | extraParams.set("resource", input.resource); |
| 717 | } |
| 718 | const additionalParameters = |
| 719 | Array.from(extraParams.keys()).length > 0 ? extraParams : undefined; |
| 720 | const response = await oauth.refreshTokenGrantRequest( |
| 721 | as, |
| 722 | client, |
| 723 | clientAuth, |
| 724 | input.refreshToken, |
| 725 | { |
| 726 | ...oauth4webapiRequestOptions( |
| 727 | input.tokenUrl, |
| 728 | input.timeoutMs, |
| 729 | input.endpointUrlPolicy, |
| 730 | input.fetch, |
| 731 | ), |
| 732 | additionalParameters, |
| 733 | }, |
| 734 | ); |
| 735 | const result = await oauth.processRefreshTokenResponse( |
| 736 | as, |
| 737 | client, |
| 738 | (await stripIdToken(response)).response, |
| 739 | ); |
| 740 | return tokenResponseFrom(result); |
| 741 | }, |
| 742 | catch: (cause) => cause, |
| 743 | }).pipe(Effect.catch(failOAuth2WithHttpSummary)); |
| 744 | |
| 745 | // --------------------------------------------------------------------------- |
| 746 | // Refresh-needed predicate |
no test coverage detected