MCPcopy
hub / github.com/upstash/context7 / refreshAccessToken

Function refreshAccessToken

packages/cli/src/utils/auth.ts:87–104  ·  view source on GitHub ↗
(refreshToken: string)

Source from the content-addressed store, hash-verified

85}
86
87async function refreshAccessToken(refreshToken: string): Promise<TokenData> {
88 const response = await fetch(`${getBaseUrl()}/api/oauth/token`, {
89 method: "POST",
90 headers: { "Content-Type": "application/x-www-form-urlencoded" },
91 body: new URLSearchParams({
92 grant_type: "refresh_token",
93 client_id: CLI_CLIENT_ID,
94 refresh_token: refreshToken,
95 }).toString(),
96 });
97
98 if (!response.ok) {
99 const err = (await response.json().catch(() => ({}))) as TokenErrorResponse;
100 throw new Error(err.error_description || err.error || "Failed to refresh token");
101 }
102
103 return (await response.json()) as TokenData;
104}
105
106/**
107 * Returns a valid access token, refreshing if expired. Returns null if no

Callers 1

getValidAccessTokenFunction · 0.85

Calls 1

getBaseUrlFunction · 0.85

Tested by

no test coverage detected