Repository navigation
Description
🔴 Required Information
Please ensure all items in this section are completed to allow for efficient
triaging. Requests without complete information may be rejected / deprioritized.
If an item is not applicable to you - please mark it as N/A
Describe the Bug:
When using OAuth2 client credentials flow (M2M use case), when OpenAPI Toolkit tries to authenticate itself it fails with error
Steps to Reproduce:
Please provide a numbered list of steps to reproduce the behavior:
- Setup OPENAPI_TOOLSET with auth_scheme, clientCredentials
- Get agent to invoke any tool
Expected Behavior:
Agent will get credentials and then proceed to make authenticated API call
Observed Behavior:
Tool call will fail and crash
google/adk/auth/auth_handler.py", line 186, in generate_auth_uri
scopes = list (scopes.keys))
٨٨٨٨٨٨٨٨٨٨٨
AttributeError: 'NoneType' object has no attribute 'keys'Environment Details:
- ADK Library Version (pip show google-adk): v1.30.0
- Desktop OS:** [e.g., macOS, Linux, Windows]: macOS
- Python Version (python -V): 3.13.11
Model Information:
- Are you using LiteLLM: No
- Which model is being used: (e.g., gemini-2.5-pro): GPT-4-o
🟡 Optional Information
Providing this information greatly speeds up the resolution process.
Regression:
Did this work in a previous version of ADK? If so, which one?
- No
Logs:
Attached log.txt
**Additional Context:**
Add any other context about the problem here.
**Minimal Reproduction Code:**
Please provide a code snippet or a link to a Gist/repo that isolates the issue.
```python
import pathlib
from google.adk import Agent
from google.adk.skills import load_skill_from_dir, models
from google.adk.tools.skill_toolset import SkillToolset
from google.adk.models.lite_llm import LiteLlm
from fastapi.openapi.models import OAuth2, OAuthFlows, OAuthFlowClientCredentials
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import (
OpenAPIToolset,
)
from google.adk.auth import AuthCredential, AuthCredentialTypes, OAuth2Auth
import asyncio
import uuid # For unique session IDs
from dotenv import load_dotenv
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
# --- OpenAPI Tool Imports ---
from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_toolset import (
OpenAPIToolset,
)
auth_scheme = OAuth2(
flows=OAuthFlows(
clientCredentials=OAuthFlowClientCredentials(tokenUrl="https://httpbin.org")
)
)
auth_credential = AuthCredential(
auth_type=AuthCredentialTypes.OAUTH2,
oauth2=OAuth2Auth(client_id="CLIENT_ID", client_secret="CLIENT_SECRET"),
)
OPENAPI_TOOLSET = OpenAPIToolset(
spec_str=openapi_spec_string,
spec_str_type="json",
auth_scheme=auth_scheme,
auth_credential=auth_credential,
)
# --- Constants ---
APP_NAME_OPENAPI = "openapi_petstore_app"
USER_ID_OPENAPI = "user_openapi_1"
SESSION_ID_OPENAPI = f"session_openapi_{uuid.uuid4()}" # Unique session ID
AGENT_NAME_OPENAPI = "petstore_manager_agent"
GEMINI_MODEL = "gemini-2.0-flash"
# --- Agent Definition ---
root_agent = LlmAgent(
name=AGENT_NAME_OPENAPI,
model="gpt-4-o",
tools=[OPENAPI_TOOLSET.get_tool("list_pets")], # Pass the list of RestApiTool objects
instruction="""You are a Pet Store assistant managing pets via an API.
Use the available tools to fulfill user requests.
When creating a pet, confirm the details echoed back by the API.
When listing pets, mention any filters used (like limit or status).
When showing a pet by ID, state the ID you requested.
""",
description="Manages a Pet Store using tools generated from an OpenAPI spec.",
)
How often has this issue occurred?:
- Always (100%)
Activity
[-]OpenApiToolkit OAuth Client Credential flow does not work[/-][+]OpenApiToolkit OAuth Client Credential (M2M) flow - 'NoneType' object has no attribute 'keys'[/+]pandego commentedon Apr 15, 2026
I dug through the ADK auth path locally and this looks like two bugs stacked together, not just the
NoneTypeone.What seems to be happening:
AuthHandler.generate_auth_request()treats any OAuth2 scheme as if it needs an interactive auth URI.clientCredentials, that is the wrong path. There is no browser authorization step, it should go straight to token exchange.generate_auth_uri()assumesflows.clientCredentials.scopesis always a dict and doeslist(scopes.keys()), but in FastAPI'sOAuthFlowClientCredentialsthat field is optional, soNoneis valid and crashes here.So I think the minimal bug is:
generate_auth_request()should special-case client-credentials flow and skip auth-URI generation entirely.I saw the same assumption in
src/google/adk/auth/oauth2_credential_util.pytoo:So even after fixing
auth_handler.py, that helper likely also needsscopes = auth_scheme.flows.clientCredentials.scopes or {}.The good news is that the exchange path already seems to exist.
credential_manager.pyexplicitly detects client-credentials flow andoauth2_credential_exchanger.pyalready has_exchange_client_credentials(), so this looks more like the interactive-auth path is being entered when it should not be.Short version: I would treat
None scopesas the symptom, but the real fix isclientCredentials != authorizationCodein the auth-request flow.A temporary workaround for repro purposes is to pass
scopes={}inOAuthFlowClientCredentials(...), but I would not rely on that as the actual fix because M2M should not needcreate_authorization_url()at all.llalitkumarrr commentedon Apr 20, 2026
Hello @NicolasCwy and @pandego
Thank you for sharing your input. We see that there are two PRs linked to this issue that are currently being reviewed. In the meantime, could you please take a look at them and let us know if they resolve the issue?
NicolasCwy commentedon Apr 23, 2026
Tested the fix by @sqsge and there is no crash but like @pandego mentioned, the auth flow is still interactive when it has all the details to perform the credential exchange. I can open another issue for this if needed
llalitkumarrr commentedon Apr 23, 2026
Hello @NicolasCwy ,
Thank you for your inputs.
Hello @DeanChensj ,
Could you please take a look at this?
fix(auth): handle missing client-credentials scopes safely
fix(auth): handle missing client-credentials scopes safely