Skip to content

Commit f8e0ac8

Browse files
RaghuRaghunandanKumar
authored andcommitted
fix(auth): allow configuring OAuth prompt parameter
AuthHandler always sent prompt=consent when generating OAuth authorization URLs, which blocked silent-auth flows even when the tool configuration needed a different prompt mode. Add an optional prompt field to OAuth2Auth, preserve consent as the default, and honor custom values such as prompt=none when building the authorization URL. Extend auth handler tests to cover both the default and a custom override.
1 parent ad8b6c7 commit f8e0ac8

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/google/adk/auth/auth_credential.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class OAuth2Auth(BaseModelWithConfig):
8787
expires_at: int | None = None
8888
expires_in: int | None = None
8989
audience: str | None = None
90+
prompt: str | None = None
9091
code_verifier: str | None = None
9192
code_challenge_method: str | None = None
9293
token_endpoint_auth_method: (

src/google/adk/auth/auth_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def generate_auth_uri(
197197
)
198198
params = {
199199
"access_type": "offline",
200-
"prompt": "consent",
200+
"prompt": auth_credential.oauth2.prompt or "consent",
201201
}
202202
if auth_credential.oauth2.audience:
203203
params["audience"] = auth_credential.oauth2.audience

tests/unittests/auth/test_auth_handler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def create_authorization_url(self, url, **kwargs):
6666
params = f"client_id={self.client_id}&scope={self.scope}"
6767
if kwargs.get("audience"):
6868
params += f"&audience={kwargs.get('audience')}"
69+
if kwargs.get("prompt"):
70+
params += f"&prompt={kwargs.get('prompt')}"
6971
return f"{url}?{params}", "mock_state"
7072

7173
def fetch_token(
@@ -250,6 +252,25 @@ def test_generate_auth_uri_with_audience_and_prompt(
250252
result = handler.generate_auth_uri()
251253

252254
assert "audience=test_audience" in result.oauth2.auth_uri
255+
assert "prompt=consent" in result.oauth2.auth_uri
256+
257+
@patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session)
258+
def test_generate_auth_uri_with_custom_prompt(
259+
self, openid_auth_scheme, oauth2_credentials
260+
):
261+
"""Test generating an auth URI with a custom prompt override."""
262+
oauth2_credentials.oauth2.prompt = "none"
263+
exchanged = oauth2_credentials.model_copy(deep=True)
264+
265+
config = AuthConfig(
266+
auth_scheme=openid_auth_scheme,
267+
raw_auth_credential=oauth2_credentials,
268+
exchanged_auth_credential=exchanged,
269+
)
270+
handler = AuthHandler(config)
271+
result = handler.generate_auth_uri()
272+
273+
assert "prompt=none" in result.oauth2.auth_uri
253274

254275
@patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session)
255276
def test_generate_auth_uri_openid(

0 commit comments

Comments
 (0)