MCPcopy Create free account
hub / github.com/arctic-cli/interface / ensureOauthAccessToken

Function ensureOauthAccessToken

packages/arctic/src/provider/usage.ts:825–844  ·  view source on GitHub ↗
(auth: Extract<Auth.Info, { type: "oauth" }>, providerID: string)

Source from the content-addressed store, hash-verified

823 }
824
825 async function ensureOauthAccessToken(auth: Extract<Auth.Info, { type: "oauth" }>, providerID: string): Promise<string> {
826 let token = auth.access
827 if (!token || auth.expires <= Date.now() + TOKEN_REFRESH_BUFFER_MS) {
828 const refreshed = await refreshAccessToken(auth.refresh)
829 if (refreshed.type === "failed") {
830 throw new Error("Failed to refresh Codex token. Run `arctic auth codex` to reconnect your account.")
831 }
832
833 const updated: Extract<Auth.Info, { type: "oauth" }> = {
834 type: "oauth",
835 access: refreshed.access,
836 refresh: refreshed.refresh,
837 expires: refreshed.expires,
838 enterpriseUrl: auth.enterpriseUrl,
839 }
840 await Auth.set(providerID, updated)
841 token = refreshed.access
842 }
843 return token
844 }
845
846 function resolveAccountId(accountId: string | undefined, tokenSource: string): string {
847 if (accountId) return accountId

Callers 1

resolveCodexCredentialsFunction · 0.85

Calls 2

refreshAccessTokenFunction · 0.90
setMethod · 0.45

Tested by

no test coverage detected