MCPcopy
hub / github.com/codeaashu/claude-code / createAndStoreApiKey

Function createAndStoreApiKey

src/services/oauth/client.ts:311–342  ·  view source on GitHub ↗
(
  accessToken: string,
)

Source from the content-addressed store, hash-verified

309}
310
311export async function createAndStoreApiKey(
312 accessToken: string,
313): Promise<string | null> {
314 try {
315 const response = await axios.post(getOauthConfig().API_KEY_URL, null, {
316 headers: { Authorization: `Bearer ${accessToken}` },
317 })
318
319 const apiKey = response.data?.raw_key
320 if (apiKey) {
321 await saveApiKey(apiKey)
322 logEvent('tengu_oauth_api_key', {
323 status:
324 'success' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
325 statusCode: response.status,
326 })
327 return apiKey
328 }
329 return null
330 } catch (error) {
331 logEvent('tengu_oauth_api_key', {
332 status:
333 'failure' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
334 error: (error instanceof Error
335 ? error.message
336 : String(
337 error,
338 )) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
339 })
340 throw error
341 }
342}
343
344export function isOAuthTokenExpired(expiresAt: number | null): boolean {
345 if (expiresAt === null) {

Callers 1

installOAuthTokensFunction · 0.85

Calls 4

getOauthConfigFunction · 0.85
saveApiKeyFunction · 0.85
logEventFunction · 0.85
postMethod · 0.80

Tested by

no test coverage detected