Skip to content

Feature/auth flow - #457

Closed
cpunion wants to merge 10 commits into
google:mainfrom
cpunion:feature/auth-flow
Closed

Feature/auth flow#457
cpunion wants to merge 10 commits into
google:mainfrom
cpunion:feature/auth-flow

Conversation

@cpunion

@cpunion cpunion commented Jan 1, 2026

Copy link
Copy Markdown

Base on:

#455 feat(auth): add OAuth2/OIDC authentication package

- Add AuthConfig, AuthCredential, AuthScheme types
- Add AuthHandler for OAuth2 flow orchestration
- Add CredentialManager and CredentialService for token management
- Add OAuth2 token exchange helpers
- Add unit tests for auth package
Add support for tools to request authentication credentials during execution:

- Add RequestedAuthConfigs field to EventActions for storing auth requests
- Implement GenerateAuthEvent to convert auth requests to adk_request_credential function calls
- Add RequestAuthConfig method to ToolContext for tools to request authentication
- Add AuthConfig field to Tool interface for tools to declare auth requirements
- Integrate auth event generation into the LLM base flow

Also fix test comparisons to ignore RequestedAuthConfigs field initialization
and add UTC timezone setup in database tests for consistent timestamp formatting.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @cpunion, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the agent's capabilities by introducing a robust and flexible authentication framework. It allows agents to dynamically request and manage user credentials for interacting with authenticated APIs, particularly for OAuth2 and OpenID Connect. The new system includes dedicated components for defining authentication schemes, handling credential exchange and refresh, and integrates seamlessly into the agent's execution flow to enable a 'Surgical Resumption' pattern, where tools can pause for user authentication and then automatically resume once credentials are provided. This foundational work enables more secure and interactive agent behaviors.

Highlights

  • New Authentication Package: Introduced a comprehensive auth package providing structures and logic for various authentication schemes, including API Key, HTTP (Bearer), OAuth2, and OpenID Connect.
  • Credential Management Lifecycle: Implemented a CredentialManager to orchestrate the full lifecycle of credentials, handling loading, exchanging (e.g., auth code to access token), refreshing expired tokens, and persisting credentials.
  • OAuth Flow Handling: Added an AuthHandler to facilitate OAuth2 and OpenID Connect flows, including the generation of authorization URIs and the processing of authentication responses.
  • Surgical Resumption for Tools: Integrated the authentication flow into the core agent execution logic (llminternal/base_flow.go) to support 'Surgical Resumption,' allowing tools to re-execute automatically after a user provides necessary authentication credentials.
  • Session Event Enhancements: Updated session.EventActions to include RequestedAuthConfigs, enabling agents to signal when a tool requires user authentication, which is then translated into adk_request_credential function calls.
  • Dependency Updates: Updated the golang.org/x/oauth2 dependency to v0.34.0 and added gopkg.in/yaml.v3 to support new functionalities.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive authentication package to handle various auth flows, primarily OAuth2. It includes new data structures for auth schemes and credentials, a credential manager for handling the token lifecycle (exchange, refresh), and integration into the core agent flow for requesting and processing user credentials. The changes are extensive, adding a new auth package and modifying several core components to support the new functionality. The implementation appears to be a faithful port of the Python ADK's auth logic. My review focuses on correctness and maintainability of the new Go code, and I've identified a few areas for improvement.

Comment thread internal/toolinternal/context.go Outdated
Comment thread auth/auth_config.go
Comment thread internal/llminternal/other_processors.go Outdated
Comment thread internal/toolinternal/context.go
@cpunion

cpunion commented Jan 1, 2026

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive authentication package (auth) to handle various authentication schemes, with a focus on OAuth2/OIDC flows. The changes are extensive, adding new data structures for auth configurations, credentials, and schemes, along with handlers and managers to orchestrate the entire authentication lifecycle, including credential exchange and token refresh.

The implementation correctly integrates with the existing agent and tool execution flow by introducing:

  • An authPreprocessor to handle user-provided credentials and resume tool execution.
  • An adk_request_credential system tool to request user authorization.
  • New methods on the tool.Context for tools to interact with the auth system.

The code is well-structured and includes thorough testing for the new components. My review includes a couple of suggestions to improve the robustness of credential key generation and clarify the behavior of the credential refresh logic on failure. Overall, this is a solid and well-engineered feature addition.

Comment thread auth/auth_config.go
Comment on lines +81 to +84
if schemePart == "" && credPart == "" {
return "adk_" + uuid.NewString(), nil
}
return fmt.Sprintf("adk_%s_%s", schemePart, credPart), nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current string formatting for the credential key can result in keys with double underscores (e.g., adk__credpart) or trailing underscores if either schemePart or credPart is empty. A more robust approach would be to conditionally build the key parts and then join them. This ensures a clean, well-formed key in all cases.

Note: You'll also need to add "strings" to your imports for this change.

Suggested change
if schemePart == "" && credPart == "" {
return "adk_" + uuid.NewString(), nil
}
return fmt.Sprintf("adk_%s_%s", schemePart, credPart), nil
parts := []string{"adk"}
if schemePart != "" {
parts = append(parts, schemePart)
}
if credPart != "" {
parts = append(parts, credPart)
}
if len(parts) == 1 {
return "adk_" + uuid.NewString(), nil
}
return strings.Join(parts, "_"), nil


refreshed, err := ref.Refresh(ctx, cred, m.authConfig.AuthScheme)
if err != nil {
return cred, false, fmt.Errorf("failed to refresh credential: %w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When a credential refresh fails, this function returns the original (and likely expired) credential along with an error. While the caller currently handles this correctly, it's safer for this function to return a nil credential on failure. This makes the function's contract clearer: a non-nil credential is only returned on success.

Suggested change
return cred, false, fmt.Errorf("failed to refresh credential: %w", err)
return nil, false, fmt.Errorf("failed to refresh credential: %w", err)

@cpunion cpunion closed this Jan 4, 2026
@cpunion
cpunion deleted the feature/auth-flow branch January 4, 2026 10:01
@cpunion
cpunion restored the feature/auth-flow branch January 4, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant