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

Function refreshAccessToken

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

Source from the content-addressed store, hash-verified

1082};
1083
1084export const refreshAccessToken = (
1085 input: RefreshAccessTokenInput,
1086): Effect.Effect<OAuth2TokenResponse, OAuth2Error> =>
1087 Effect.tryPromise({
1088 try: async () => {
1089 const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, {
1090 idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported,
1091 endpointUrlPolicy: input.endpointUrlPolicy,
1092 });
1093 const client: oauth.Client = { client_id: input.clientId };
1094 const clientAuth = pickClientAuth(
1095 input.clientSecret,
1096 input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD,
1097 );
1098 const extraParams = new URLSearchParams();
1099 if (input.scopes && input.scopes.length > 0) {
1100 extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " "));
1101 }
1102 if (input.resource) {
1103 extraParams.set("resource", input.resource);
1104 }
1105 const additionalParameters =
1106 Array.from(extraParams.keys()).length > 0 ? extraParams : undefined;
1107 const response = await oauth.refreshTokenGrantRequest(
1108 as,
1109 client,
1110 clientAuth,
1111 input.refreshToken,
1112 {
1113 ...oauth4webapiRequestOptions(
1114 input.tokenUrl,
1115 input.timeoutMs,
1116 input.endpointUrlPolicy,
1117 input.fetch,
1118 ),
1119 additionalParameters,
1120 },
1121 );
1122 const result = await oauth.processRefreshTokenResponse(
1123 as,
1124 client,
1125 (await stripIdToken(response)).response,
1126 );
1127 return tokenResponseFrom(as, result);
1128 },
1129 catch: (cause) => cause,
1130 }).pipe(
1131 Effect.catch(failOAuth2WithHttpSummary),
1132 withTokenRequestSpan({
1133 grantType: "refresh_token",
1134 tokenUrl: input.tokenUrl,
1135 clientAuth: input.clientAuth,
1136 hasResource: input.resource !== undefined,
1137 }),
1138 );
1139
1140// ---------------------------------------------------------------------------
1141// RFC 8693 token exchange → Identity Assertion JWT Authorization Grant

Callers 2

performTokenRefreshFunction · 0.90

Calls 7

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

Tested by

no test coverage detected