MCPcopy Index your code
hub / github.com/21st-dev/1code / authenticateMcp

Method authenticateMcp

src/main/lib/credential-manager.ts:351–385  ·  view source on GitHub ↗

* Authenticate MCP source via OAuth

(
    source: LoadedSource,
    callbacks: OAuthCallbacks
  )

Source from the content-addressed store, hash-verified

349 * Authenticate MCP source via OAuth
350 */
351 private async authenticateMcp(
352 source: LoadedSource,
353 callbacks: OAuthCallbacks
354 ): Promise<AuthResult> {
355 if (!source.config.mcp?.url) {
356 return { success: false, error: 'MCP URL not configured' };
357 }
358
359 try {
360 const oauth = new CraftOAuth(
361 { mcpBaseUrl: getMcpBaseUrl(source.config.mcp.url) },
362 callbacks
363 );
364
365 const { tokens, clientId } = await oauth.authenticate();
366
367 // Save the credentials
368 await this.save(source, {
369 value: tokens.accessToken,
370 refreshToken: tokens.refreshToken,
371 expiresAt: tokens.expiresAt,
372 clientId,
373 tokenType: tokens.tokenType,
374 });
375
376 // Mark source as authenticated in config.json
377 markSourceAuthenticated(source.workspaceRootPath, source.config.slug);
378
379 return { success: true };
380 } catch (error) {
381 const message = error instanceof Error ? error.message : String(error);
382 callbacks.onError(message);
383 return { success: false, error: message };
384 }
385 }
386
387 /**
388 * Authenticate Google API source via Google OAuth

Callers 1

authenticateMethod · 0.95

Calls 3

authenticateMethod · 0.95
saveMethod · 0.95
getMcpBaseUrlFunction · 0.90

Tested by

no test coverage detected