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

Function ensureGoogleAccessToken

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

Source from the content-addressed store, hash-verified

1040 }
1041
1042 async function ensureGoogleAccessToken(auth: Extract<Auth.Info, { type: "oauth" }>, providerID: string): Promise<string> {
1043 const refreshParts = parseRefreshParts(auth.refresh)
1044 let token = auth.access
1045 if (!token || auth.expires <= Date.now() + 5 * 60 * 1000) {
1046 await logDebug("accessToken.refreshing")
1047 const client = new OAuth2Client({
1048 clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
1049 clientSecret: "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",
1050 })
1051
1052 client.setCredentials({
1053 refresh_token: refreshParts.refreshToken || auth.refresh,
1054 access_token: auth.access,
1055 expiry_date: auth.expires,
1056 })
1057
1058 const { token: accessToken } = await client.getAccessToken()
1059
1060 if (!accessToken) {
1061 await logDebug("accessToken.refresh_failed")
1062 throw new Error("Failed to refresh Google access token. Re-authenticate with `arctic auth login`.")
1063 }
1064
1065 const updated: Extract<Auth.Info, { type: "oauth" }> = {
1066 type: "oauth",
1067 access: accessToken,
1068 refresh: auth.refresh,
1069 expires: auth.expires,
1070 }
1071 await Auth.set(providerID, updated)
1072 token = accessToken
1073 await logDebug("accessToken.refresh_success")
1074 }
1075 return token
1076 }
1077
1078 async function loadManagedProject(accessToken: string, projectId?: string): Promise<any | null> {
1079 const metadata: { [key: string]: string } = {

Callers 1

fetchGoogleUsageFunction · 0.85

Calls 3

parseRefreshPartsFunction · 0.70
logDebugFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected