MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / refreshTokens

Function refreshTokens

packages/cli/src/auth/oauth.ts:173–206  ·  view source on GitHub ↗
(
  refresh_token: string,
  opts: RefreshOptions = {},
)

Source from the content-addressed store, hash-verified

171}
172
173export async function refreshTokens(
174 refresh_token: string,
175 opts: RefreshOptions = {},
176): Promise<OAuthTokens> {
177 const clientId = resolveClientId();
178 const fetchImpl = opts.fetchImpl ?? fetch;
179 const body = new URLSearchParams({
180 grant_type: "refresh_token",
181 refresh_token,
182 client_id: clientId,
183 });
184
185 const res = await fetchImpl(tokenEndpoint(), {
186 method: "POST",
187 headers: {
188 "content-type": "application/x-www-form-urlencoded",
189 accept: "application/json",
190 },
191 body: body.toString(),
192 });
193
194 if (res.status === 400 || res.status === 401) {
195 throw ErrRefreshFailed(await safeText(res));
196 }
197 if (!res.ok) {
198 throw ErrApi(res.status, (await safeText(res)) || res.statusText);
199 }
200
201 const payload = await readJsonOrThrow(res);
202 const tokens = parseTokenResponse(payload);
203 // Refresh grant → preserve a refresh_token the server didn't rotate.
204 await persistOAuth(tokens, { preserveMissing: true });
205 return tokens;
206}
207
208export interface RevokeOptions extends RefreshOptions {
209 /** Hint to the server about which token we're sending (RFC 7009). */

Callers 6

refreshIfNeededFunction · 0.85
forceRefreshCredentialsFunction · 0.85
oauth.test.tsFile · 0.85
verifyFunction · 0.85
reportIdentityFunction · 0.85
runFunction · 0.85

Calls 8

resolveClientIdFunction · 0.85
tokenEndpointFunction · 0.85
ErrRefreshFailedFunction · 0.85
ErrApiFunction · 0.85
readJsonOrThrowFunction · 0.85
parseTokenResponseFunction · 0.85
persistOAuthFunction · 0.85
safeTextFunction · 0.70

Tested by

no test coverage detected