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

Function refreshAccessToken

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

Source from the content-addressed store, hash-verified

1331};
1332
1333export const refreshAccessToken = (
1334 input: RefreshAccessTokenInput,
1335): Effect.Effect<OAuth2TokenResponse, OAuth2Error> =>
1336 Effect.tryPromise({
1337 try: async () => {
1338 const as = asFromTokenUrlAndIssuer(input.tokenUrl, input.issuerUrl, {
1339 idTokenSigningAlgValuesSupported: input.idTokenSigningAlgValuesSupported,
1340 endpointUrlPolicy: input.endpointUrlPolicy,
1341 });
1342 const client: oauth.Client = { client_id: input.clientId };
1343 const clientAuth = pickClientAuth(
1344 input.clientSecret,
1345 input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD,
1346 );
1347 const extraParams = new URLSearchParams();
1348 if (input.scopes && input.scopes.length > 0) {
1349 extraParams.set("scope", input.scopes.join(input.scopeSeparator ?? " "));
1350 }
1351 if (input.resource) {
1352 extraParams.set("resource", input.resource);
1353 }
1354 const additionalParameters =
1355 Array.from(extraParams.keys()).length > 0 ? extraParams : undefined;
1356 if (input.requestFormat === "json") {
1357 const response = await jsonTokenEndpointRequest({
1358 tokenUrl: input.tokenUrl,
1359 clientId: input.clientId,
1360 clientSecret: input.clientSecret,
1361 clientAuth: input.clientAuth ?? DEFAULT_CLIENT_AUTH_METHOD,
1362 grantType: "refresh_token",
1363 parameters: {
1364 refresh_token: input.refreshToken,
1365 ...(input.scopes && input.scopes.length > 0
1366 ? { scope: input.scopes.join(input.scopeSeparator ?? " ") }
1367 : {}),
1368 ...(input.resource ? { resource: input.resource } : {}),
1369 },
1370 timeoutMs: input.timeoutMs,
1371 endpointUrlPolicy: input.endpointUrlPolicy,
1372 fetch: input.fetch,
1373 });
1374 return await processTokenEndpointResponse(as, client, response);
1375 }
1376 const response = await oauth.refreshTokenGrantRequest(
1377 as,
1378 client,
1379 clientAuth,
1380 input.refreshToken,
1381 {
1382 ...oauth4webapiRequestOptions(
1383 input.tokenUrl,
1384 input.timeoutMs,
1385 input.endpointUrlPolicy,
1386 input.fetch,
1387 ),
1388 additionalParameters,
1389 },
1390 );

Callers 2

performTokenRefreshFunction · 0.90

Calls 10

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

Tested by

no test coverage detected