* Authenticate source via OAuth * * Handles both MCP OAuth and Gmail OAuth flows. * On success, credentials are automatically saved.
(
source: LoadedSource,
callbacks?: OAuthCallbacks
)
| 310 | * On success, credentials are automatically saved. |
| 311 | */ |
| 312 | async authenticate( |
| 313 | source: LoadedSource, |
| 314 | callbacks?: OAuthCallbacks |
| 315 | ): Promise<AuthResult> { |
| 316 | const defaultCallbacks: OAuthCallbacks = { |
| 317 | onStatus: (msg) => debug(`[SourceCredentialManager] ${msg}`), |
| 318 | onError: (err) => debug(`[SourceCredentialManager] Error: ${err}`), |
| 319 | }; |
| 320 | const cb = callbacks || defaultCallbacks; |
| 321 | |
| 322 | // Google APIs use Google OAuth |
| 323 | if (source.config.provider === 'google') { |
| 324 | return this.authenticateGoogle(source, cb); |
| 325 | } |
| 326 | |
| 327 | // Slack APIs use Slack OAuth |
| 328 | if (source.config.provider === 'slack') { |
| 329 | return this.authenticateSlack(source, cb); |
| 330 | } |
| 331 | |
| 332 | // Microsoft APIs use Microsoft OAuth |
| 333 | if (source.config.provider === 'microsoft') { |
| 334 | return this.authenticateMicrosoft(source, cb); |
| 335 | } |
| 336 | |
| 337 | // MCP OAuth flow |
| 338 | if (source.config.type === 'mcp' && source.config.mcp?.authType === 'oauth') { |
| 339 | return this.authenticateMcp(source, cb); |
| 340 | } |
| 341 | |
| 342 | return { |
| 343 | success: false, |
| 344 | error: `Source ${source.config.slug} does not use OAuth authentication`, |
| 345 | }; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Authenticate MCP source via OAuth |
nothing calls this directly
no test coverage detected