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

Function refreshAccessToken

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

Source from the content-addressed store, hash-verified

641};
642
643export 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

Callers 2

performTokenRefreshFunction · 0.90

Calls 6

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

Tested by

no test coverage detected