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

Function refreshAccessToken

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

Source from the content-addressed store, hash-verified

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

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