{"record":{"id":"767745d9192025da","repo":"google-gemini/gemini-cli","slug":"oauth2-authentication-for-agent-this-agentname","errorCode":null,"errorMessage":"OAuth2 authentication for agent \"${this.agentName}\" requires a client_id. Add client_id to the auth config in your agent definition.","messagePattern":"OAuth2 authentication for agent \"(.+?)\" requires a client_id\\. Add client_id to the auth config in your agent definition\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/auth-provider/oauth2-provider.ts","lineNumber":213,"sourceCode":"      debugLogger.debug(\n        `[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`,\n      );\n      const resolver = new DefaultAgentCardResolver();\n      const card = await resolver.resolve(this.agentCardUrl, '');\n      this.mergeAgentCardDefaults(card);\n    } catch (error) {\n      debugLogger.warn(\n        `[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`,\n      );\n    }\n  }\n\n  /**\n   * Run a full OAuth 2.0 Authorization Code + PKCE flow through the browser.\n   */\n  private async authenticateInteractively(): Promise<OAuthToken> {\n    if (!this.config.client_id) {\n      throw new Error(\n        `OAuth2 authentication for agent \"${this.agentName}\" requires a client_id. ` +\n          'Add client_id to the auth config in your agent definition.',\n      );\n    }\n    if (!this.authorizationUrl || !this.tokenUrl) {\n      throw new Error(\n        `OAuth2 authentication for agent \"${this.agentName}\" requires authorization_url and token_url. ` +\n          'Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.',\n      );\n    }\n\n    const flowConfig: OAuthFlowConfig = {\n      clientId: this.config.client_id,\n      clientSecret: this.config.client_secret,\n      authorizationUrl: this.authorizationUrl,\n      tokenUrl: this.tokenUrl,\n      scopes: this.scopes,\n    };","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agents/auth-provider/oauth2-provider.ts#L195-L231","documentation":"OAuth2AuthProvider.authenticateInteractively requires config.client_id before it can build an OAuth flow; without it the Authorization Code + PKCE flow has no client identity. The error names the agent and points the user to the auth config in the agent definition. It fires during the interactive browser flow, after the provider has already tried cached tokens.","triggerScenarios":"An agent whose auth.type is 'oauth' (mapped to oauth2) but the frontmatter omits client_id; client_id set to an empty string; the field renamed in an edit; an auto-generated config missing the field.","commonSituations":"Copy-pasting an oauth example without the client_id; expecting the agent card to supply client_id (the card supplies URLs but not the client_id, which is the integrator's own app registration); a typo in the key (e.g. clientId camelCase).","solutions":["Add client_id to the auth block in the agent frontmatter.","Register an OAuth client with the provider and copy the issued client_id.","Use the snake_case key 'client_id' (not clientId) to match the schema.","If the server supports a different auth scheme, switch to one that does not need a client_id."],"exampleFix":"# before\nauth:\n  type: oauth\n  client_secret: secret\n\n# after\nauth:\n  type: oauth\n  client_id: my-registered-client-id\n  client_secret: secret","handlingStrategy":"validation","validationCode":"if (authConfig.type === 'oauth2' && !authConfig.client_id) {\n  throw new Error('oauth2 auth requires a client_id in the agent definition.');\n}\nawait A2AAuthProviderFactory.create({ authConfig, agentName });","typeGuard":"function hasClientId(c: { client_id?: string }): c is { client_id: string } {\n  return typeof c.client_id === 'string' && c.client_id.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Register an OAuth client and copy its client_id into frontmatter.","Use the snake_case key client_id (not clientId).","Validate oauth2 configs for required fields at load time."],"tags":["auth","oauth2","config","client-id"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}