Skip to content

OAuth2 client-credentials exchange ignores configured scopes #8388

In review

Description

@sumedh-aerram

Configured OAuth2 client-credentials scopes are omitted from the token POST. This grant has no authorization redirect to carry them, so providers can return default permissions or reject the request.

The token POST should include scope=read:items. Actual: grant_type=client_credentials is present, but scope is absent.

Environment: ADK main (2.15.x), Python 3.11.

Offline reproduction (mocked transport/storage; no network access):

"""Offline: capture the actual Authlib client-credentials POST body."""
import asyncio
from urllib.parse import parse_qs
from unittest.mock import patch

from fastapi.openapi.models import OAuth2, OAuthFlows, OAuthFlowClientCredentials
from google.adk.auth.auth_credential import AuthCredential, AuthCredentialTypes, OAuth2Auth
from google.adk.auth.exchanger.oauth2_credential_exchanger import OAuth2CredentialExchanger
from requests import Response


async def main():
    scheme = OAuth2(flows=OAuthFlows(clientCredentials=OAuthFlowClientCredentials(
        tokenUrl="https://example.invalid/token", scopes={"read:items": "Read items"},
    )))
    credential = AuthCredential(auth_type=AuthCredentialTypes.OAUTH2,
        oauth2=OAuth2Auth(client_id="client", client_secret="secret"))
    bodies = []

    def send(session, request, **kwargs):
        bodies.append(parse_qs(request.body))
        response = Response()
        response.status_code = 200
        response._content = b'{"access_token":"fresh","token_type":"Bearer","expires_in":3600}'
        response.headers["Content-Type"] = "application/json"
        return response

    with patch("requests.sessions.Session.send", send):
        result = await OAuth2CredentialExchanger().exchange(credential, scheme)
    print("configured scopes:", sorted(scheme.flows.clientCredentials.scopes))
    print("actual grant_type:", bodies[0].get("grant_type"))
    print("actual scope:", bodies[0].get("scope"))
    print("exchange succeeded:", result.was_exchanged)
    assert "scope" not in bodies[0]


asyncio.run(main())

Activity

  1. added
    core
    on Nov 30, 2026
  2. sanketpatil06 commented on Dec 1, 2026

    @sanketpatil06

    Hi @sumedh-aerram, we've reproduced this on main. OAuth2CredentialExchanger._exchange_client_credentials() calls client.fetch_token() without extracting configured scopes from OAuth2 or OpenIdConnectWithConfig schemes. Your PR #8389 is under review and will be merged once approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions