MCPcopy Create free account
hub / github.com/freecodexyz/free-code / getClaudeAIOAuthTokensAsync

Function getClaudeAIOAuthTokensAsync

src/utils/auth.ts:1456–1479  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1454 * (which don't hit the keychain), and only uses async for storage reads.
1455 */
1456export async function getClaudeAIOAuthTokensAsync(): Promise<OAuthTokens | null> {
1457 if (isBareMode()) return null
1458
1459 // Env var and FD tokens are sync and don't hit the keychain
1460 if (
1461 process.env.CLAUDE_CODE_OAUTH_TOKEN ||
1462 getOAuthTokenFromFileDescriptor()
1463 ) {
1464 return getClaudeAIOAuthTokens()
1465 }
1466
1467 try {
1468 const secureStorage = getSecureStorage()
1469 const storageData = await secureStorage.readAsync()
1470 const oauthData = storageData?.claudeAiOauth
1471 if (!oauthData?.accessToken) {
1472 return null
1473 }
1474 return oauthData
1475 } catch (error) {
1476 logError(error)
1477 return null
1478 }
1479}
1480
1481// In-flight promise for deduplicating concurrent calls
1482let pendingRefreshCheck: Promise<boolean> | null = null

Callers 2

handleOAuth401ErrorImplFunction · 0.85

Calls 4

isBareModeFunction · 0.85
getSecureStorageFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected