MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / refreshAccessToken

Function refreshAccessToken

packages/core/sdk/src/oauth-helpers.ts:811–865  ·  view source on GitHub ↗
(
  input: RefreshAccessTokenInput,
)

Source from the content-addressed store, hash-verified

809};
810
811export const refreshAccessToken = (
812 input: RefreshAccessTokenInput,
813): Effect.Effect<OAuth2TokenResponse, OAuth2Error> =>
814 Effect.tryPromise({
815 try: async () => {
816 const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, {
817 idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported,
818 endpointUrlPolicy: input.endpointUrlPolicy,
819 });
820 const client: oauth.Client = { client_id: input.clientId };
821 const clientAuth = pickClientAuth(
822 input.clientSecret,
823 input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD,
824 );
825 const extraParams = new URLSearchParams();
826 if (input.scopes && input.scopes.length > 0) {
827 extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " "));
828 }
829 if (input.resource) {
830 extraParams.set("resource", input.resource);
831 }
832 const additionalParameters =
833 Array.from(extraParams.keys()).length > 0 ? extraParams : undefined;
834 const response = await oauth.refreshTokenGrantRequest(
835 as,
836 client,
837 clientAuth,
838 input.refreshToken,
839 {
840 ...oauth4webapiRequestOptions(
841 input.tokenUrl,
842 input.timeoutMs,
843 input.endpointUrlPolicy,
844 input.fetch,
845 ),
846 additionalParameters,
847 },
848 );
849 const result = await oauth.processRefreshTokenResponse(
850 as,
851 client,
852 (await stripIdToken(response)).response,
853 );
854 return tokenResponseFrom(result);
855 },
856 catch: (cause) => cause,
857 }).pipe(
858 Effect.catch(failOAuth2WithHttpSummary),
859 withTokenRequestSpan({
860 grantType: "refresh_token",
861 tokenUrl: input.tokenUrl,
862 clientAuth: input.clientAuth,
863 hasResource: input.resource !== undefined,
864 }),
865 );
866
867// ---------------------------------------------------------------------------
868// Refresh-needed predicate

Callers 2

performTokenRefreshFunction · 0.90

Calls 7

asFromTokenUrlAndIssuerFunction · 0.85
pickClientAuthFunction · 0.85
stripIdTokenFunction · 0.85
tokenResponseFromFunction · 0.85
withTokenRequestSpanFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected