MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getAuthTokenSource

Function getAuthTokenSource

source code/utils/auth.ts:155–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153/** Where the auth token is being sourced from, if any. */
154// this code is closely related to isAnthropicAuthEnabled
155export function getAuthTokenSource() {
156 // --bare: API-key-only. apiKeyHelper (from --settings) is the only
157 // bearer-token-shaped source allowed. OAuth env vars, FD tokens, and
158 // keychain are ignored.
159 if (isBareMode()) {
160 if (getConfiguredApiKeyHelper()) {
161 return { source: 'apiKeyHelper' as const, hasToken: true }
162 }
163 return { source: 'none' as const, hasToken: false }
164 }
165
166 if (process.env.ANTHROPIC_AUTH_TOKEN && !isManagedOAuthContext()) {
167 return { source: 'ANTHROPIC_AUTH_TOKEN' as const, hasToken: true }
168 }
169
170 if (process.env.CLAUDE_CODE_OAUTH_TOKEN) {
171 return { source: 'CLAUDE_CODE_OAUTH_TOKEN' as const, hasToken: true }
172 }
173
174 // Check for OAuth token from file descriptor (or its CCR disk fallback)
175 const oauthTokenFromFd = getOAuthTokenFromFileDescriptor()
176 if (oauthTokenFromFd) {
177 // getOAuthTokenFromFileDescriptor has a disk fallback for CCR subprocesses
178 // that can't inherit the pipe FD. Distinguish by env var presence so the
179 // org-mismatch message doesn't tell the user to unset a variable that
180 // doesn't exist. Call sites fall through correctly — the new source is
181 // !== 'none' (cli/handlers/auth.ts → oauth_token) and not in the
182 // isEnvVarToken set (auth.ts:1844 → generic re-login message).
183 if (process.env.CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR) {
184 return {
185 source: 'CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR' as const,
186 hasToken: true,
187 }
188 }
189 return {
190 source: 'CCR_OAUTH_TOKEN_FILE' as const,
191 hasToken: true,
192 }
193 }
194
195 // Check if apiKeyHelper is configured without executing it
196 // This prevents security issues where arbitrary code could execute before trust is established
197 const apiKeyHelper = getConfiguredApiKeyHelper()
198 if (apiKeyHelper && !isManagedOAuthContext()) {
199 return { source: 'apiKeyHelper' as const, hasToken: true }
200 }
201
202 const oauthTokens = getClaudeAIOAuthTokens()
203 if (shouldUseClaudeAIAuth(oauthTokens?.scopes) && oauthTokens?.accessToken) {
204 return { source: 'claude.ai' as const, hasToken: true }
205 }
206
207 return { source: 'none' as const, hasToken: false }
208}
209
210export type ApiKeySource =
211 | 'ANTHROPIC_API_KEY'

Callers 5

getAccountInformationFunction · 0.85
validateForceLoginOrgFunction · 0.85
hasConsoleBillingAccessFunction · 0.85
authStatusFunction · 0.85

Calls 5

isBareModeFunction · 0.85
isManagedOAuthContextFunction · 0.85
shouldUseClaudeAIAuthFunction · 0.85

Tested by

no test coverage detected