adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

GmailToolset OAuth redirect_uri malformed with appended flowName parameter

Open SAMFVH opened this issue 1 year ago • 3 comments

Here's the bug report using the provided template: Describe the bug GmailToolset OAuth flow generates malformed authorization URLs where the flowName=GeneralOAuthFlow parameter is incorrectly appended to the redirect_uri value instead of being a separate query parameter, causing redirect_uri_mismatch errors in Google OAuth.

To Reproduce Steps to reproduce the behavior:

  1. Install google-adk package
  2. Create a GmailToolset with OAuth credentials:
    from google.adk.tools.google_api_tool.google_api_toolsets import GmailToolset
    
    gmail_toolset = GmailToolset(
        client_id="your-client-id",
        client_secret="your-client-secret",
        tool_filter=['gmail_users_drafts_create']
    )
    
  3. Deploy to Google Cloud Run and trigger any Gmail tool function
  4. Observe OAuth authorization URL contains malformed redirect_uri: redirect_uri=https://your-url.run.app/dev-ui/ flowName=GeneralOAuthFlow (contains a whitespace)

Expected behavior OAuth authorization URL should have properly separated query parameters:

redirect_uri=https://your-url.run.app/dev-ui/?flowName=GeneralOAuthFlow 

Note: '?' instead of whitespace or not be there at all?

Error message Error from Google OAuth:

Error 400: redirect_uri_mismatch
Request details: redirect_uri=https://my-cloud-run-app.us-central1.run.app/dev-ui/ flowName=GeneralOAuthFlow 

Note: There is a space between the URL and "flowName", indicating the flowName is being incorrectly appended to the redirect_uri value instead of being handled separately.

Desktop (please complete the following information):

  • OS: macOS
  • Python version: Python 3.13.0
  • ADK version: 1.2.1 (installed from pip)

Additional context

  • Issue occurs in google/adk/auth/auth_handler.py around line 244-250 in the generate_auth_uri() method:
  • GmailToolset constructor doesn't accept redirect_uri parameter, causing auth_credential.oauth2.redirect_uri to be None
  • The flowName parameter gets incorrectly concatenated to the redirect_uri value instead of being a separate query parameter
  • This affects all Google API toolsets using OAuth2 flows
  • Registered redirect URI in Google Cloud Console matches the base URL but fails due to the malformed parameter

SAMFVH avatar Jun 06 '25 09:06 SAMFVH

I'm observing this (4)"flowName=GeneralOAuthFlow (contains a whitespace)" in firebase auth. This may prevent firebase auth from working using Google accounts.

peterjliu avatar Jun 11 '25 18:06 peterjliu

I encountered the same issue with redirect url. I just used https://your-url.run.app/dev-ui/ without "flowName=GeneralOAuthFlow" in the oauth configuration and it worked fine.

kirupagaran avatar Aug 03 '25 11:08 kirupagaran

Hi @SAMFVH and thanks to everyone who participated in this thread.

We're currently doing some housekeeping on our issue tracker. Given the rapid pace of development and the number of updates since this was last active, there's a good chance this issue has been resolved in a newer version. To help us keep our backlog focused on current issues, we are closing this as stale.

If you're still facing this problem, could you please update to the very latest version of the library and confirm the issue still exists? If it does, please comment here, and we will be happy to reopen this issue and investigate further.

Thanks for your contribution and understanding!

jwiejulie avatar Aug 08 '25 22:08 jwiejulie