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

Function refreshAccessToken

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

Source from the content-addressed store, hash-verified

748};
749
750export const refreshAccessToken = (
751 input: RefreshAccessTokenInput,
752): Effect.Effect<OAuth2TokenResponse, OAuth2Error> =>
753 Effect.tryPromise({
754 try: async () => {
755 const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, {
756 idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported,
757 endpointUrlPolicy: input.endpointUrlPolicy,
758 });
759 const client: oauth.Client = { client_id: input.clientId };
760 const clientAuth = pickClientAuth(
761 input.clientSecret,
762 input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD,
763 );
764 const extraParams = new URLSearchParams();
765 if (input.scopes && input.scopes.length > 0) {
766 extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " "));
767 }
768 if (input.resource) {
769 extraParams.set("resource", input.resource);
770 }
771 const additionalParameters =
772 Array.from(extraParams.keys()).length > 0 ? extraParams : undefined;
773 const response = await oauth.refreshTokenGrantRequest(
774 as,
775 client,
776 clientAuth,
777 input.refreshToken,
778 {
779 ...oauth4webapiRequestOptions(
780 input.tokenUrl,
781 input.timeoutMs,
782 input.endpointUrlPolicy,
783 input.fetch,
784 ),
785 additionalParameters,
786 },
787 );
788 const result = await oauth.processRefreshTokenResponse(
789 as,
790 client,
791 (await stripIdToken(response)).response,
792 );
793 return tokenResponseFrom(result);
794 },
795 catch: (cause) => cause,
796 }).pipe(
797 Effect.catch(failOAuth2WithHttpSummary),
798 withTokenRequestSpan({
799 grantType: "refresh_token",
800 tokenUrl: input.tokenUrl,
801 clientAuth: input.clientAuth,
802 hasResource: input.resource !== undefined,
803 }),
804 );
805
806// ---------------------------------------------------------------------------
807// 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