( input: RefreshAccessTokenInput, )
| 899 | }; |
| 900 | |
| 901 | export const refreshAccessToken = ( |
| 902 | input: RefreshAccessTokenInput, |
| 903 | ): Effect.Effect<OAuth2TokenResponse, OAuth2Error> => |
| 904 | Effect.tryPromise({ |
| 905 | try: async () => { |
| 906 | const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, { |
| 907 | idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported, |
| 908 | endpointUrlPolicy: input.endpointUrlPolicy, |
| 909 | }); |
| 910 | const client: oauth.Client = { client_id: input.clientId }; |
| 911 | const clientAuth = pickClientAuth( |
| 912 | input.clientSecret, |
| 913 | input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD, |
| 914 | ); |
| 915 | const extraParams = new URLSearchParams(); |
| 916 | if (input.scopes && input.scopes.length > 0) { |
| 917 | extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " ")); |
| 918 | } |
| 919 | if (input.resource) { |
| 920 | extraParams.set("resource", input.resource); |
| 921 | } |
| 922 | const additionalParameters = |
| 923 | Array.from(extraParams.keys()).length > 0 ? extraParams : undefined; |
| 924 | const response = await oauth.refreshTokenGrantRequest( |
| 925 | as, |
| 926 | client, |
| 927 | clientAuth, |
| 928 | input.refreshToken, |
| 929 | { |
| 930 | ...oauth4webapiRequestOptions( |
| 931 | input.tokenUrl, |
| 932 | input.timeoutMs, |
| 933 | input.endpointUrlPolicy, |
| 934 | input.fetch, |
| 935 | ), |
| 936 | additionalParameters, |
| 937 | }, |
| 938 | ); |
| 939 | const result = await oauth.processRefreshTokenResponse( |
| 940 | as, |
| 941 | client, |
| 942 | (await stripIdToken(response)).response, |
| 943 | ); |
| 944 | return tokenResponseFrom(as, result); |
| 945 | }, |
| 946 | catch: (cause) => cause, |
| 947 | }).pipe( |
| 948 | Effect.catch(failOAuth2WithHttpSummary), |
| 949 | withTokenRequestSpan({ |
| 950 | grantType: "refresh_token", |
| 951 | tokenUrl: input.tokenUrl, |
| 952 | clientAuth: input.clientAuth, |
| 953 | hasResource: input.resource !== undefined, |
| 954 | }), |
| 955 | ); |
| 956 | |
| 957 | // --------------------------------------------------------------------------- |
| 958 | // Refresh-needed predicate |
no test coverage detected