getOauthProfile.ts
services/oauth/getOauthProfile.ts
54
Lines
1611
Bytes
2
Exports
6
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with file-tools, integrations. It contains 54 lines, 6 detected imports, and 2 detected exports.
Important relationships
Detected exports
getOauthProfileFromApiKeygetOauthProfileFromOauthToken
Keywords
oauthprofileresponseaxiosaccountuuidendpointresponsegetoauthconfigoauthutilsconfiglogerror
Detected imports
axiossrc/constants/oauth.jssrc/services/oauth/types.jssrc/utils/auth.jssrc/utils/config.jssrc/utils/log.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import axios from 'axios'
import { getOauthConfig, OAUTH_BETA_HEADER } from 'src/constants/oauth.js'
import type { OAuthProfileResponse } from 'src/services/oauth/types.js'
import { getAnthropicApiKey } from 'src/utils/auth.js'
import { getGlobalConfig } from 'src/utils/config.js'
import { logError } from 'src/utils/log.js'
export async function getOauthProfileFromApiKey(): Promise<
OAuthProfileResponse | undefined
> {
// Assumes interactive session
const config = getGlobalConfig()
const accountUuid = config.oauthAccount?.accountUuid
const apiKey = getAnthropicApiKey()
// Need both account UUID and API key to check
if (!accountUuid || !apiKey) {
return
}
const endpoint = `${getOauthConfig().BASE_API_URL}/api/claude_cli_profile`
try {
const response = await axios.get<OAuthProfileResponse>(endpoint, {
headers: {
'x-api-key': apiKey,
'anthropic-beta': OAUTH_BETA_HEADER,
},
params: {
account_uuid: accountUuid,
},
timeout: 10000,
})
return response.data
} catch (error) {
logError(error as Error)
}
}
export async function getOauthProfileFromOauthToken(
accessToken: string,
): Promise<OAuthProfileResponse | undefined> {
const endpoint = `${getOauthConfig().BASE_API_URL}/api/oauth/profile`
try {
const response = await axios.get<OAuthProfileResponse>(endpoint, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
timeout: 10000,
})
return response.data
} catch (error) {
logError(error as Error)
}
}