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

Function createAndStoreApiKey

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

Source from the content-addressed store, hash-verified

337}
338
339export async function createAndStoreApiKey(
340 accessToken: string,
341): Promise<string | null> {
342 try {
343 const response = await axios.post(getOauthConfig().API_KEY_URL, null, {
344 headers: { Authorization: `Bearer ${accessToken}` },
345 })
346
347 const apiKey = response.data?.raw_key
348 if (apiKey) {
349 await saveApiKey(apiKey)
350 logEvent('tengu_oauth_api_key', {
351 status:
352 'success' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
353 statusCode: response.status,
354 })
355 return apiKey
356 }
357 return null
358 } catch (error) {
359 logEvent('tengu_oauth_api_key', {
360 status:
361 'failure' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
362 error: (error instanceof Error
363 ? error.message
364 : String(
365 error,
366 )) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
367 })
368 throw error
369 }
370}
371
372export function isOAuthTokenExpired(expiresAt: number | null): boolean {
373 if (expiresAt === null) {

Callers 1

installOAuthTokensFunction · 0.85

Calls 3

getOauthConfigFunction · 0.85
saveApiKeyFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected