Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/google/adk/auth/auth_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class OAuth2Auth(BaseModelWithConfig):
expires_at: int | None = None
expires_in: int | None = None
audience: str | None = None
prompt: str | None = None
code_verifier: str | None = None
code_challenge_method: str | None = None
token_endpoint_auth_method: (
Expand Down
2 changes: 1 addition & 1 deletion src/google/adk/auth/auth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def generate_auth_uri(
)
params = {
"access_type": "offline",
"prompt": "consent",
"prompt": auth_credential.oauth2.prompt or "consent",
}
if auth_credential.oauth2.audience:
params["audience"] = auth_credential.oauth2.audience
Expand Down
21 changes: 21 additions & 0 deletions tests/unittests/auth/test_auth_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def create_authorization_url(self, url, **kwargs):
params = f"client_id={self.client_id}&scope={self.scope}"
if kwargs.get("audience"):
params += f"&audience={kwargs.get('audience')}"
if kwargs.get("prompt"):
params += f"&prompt={kwargs.get('prompt')}"
return f"{url}?{params}", "mock_state"

def fetch_token(
Expand Down Expand Up @@ -250,6 +252,25 @@ def test_generate_auth_uri_with_audience_and_prompt(
result = handler.generate_auth_uri()

assert "audience=test_audience" in result.oauth2.auth_uri
assert "prompt=consent" in result.oauth2.auth_uri

@patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session)
def test_generate_auth_uri_with_custom_prompt(
self, openid_auth_scheme, oauth2_credentials
):
"""Test generating an auth URI with a custom prompt override."""
oauth2_credentials.oauth2.prompt = "none"
exchanged = oauth2_credentials.model_copy(deep=True)

config = AuthConfig(
auth_scheme=openid_auth_scheme,
raw_auth_credential=oauth2_credentials,
exchanged_auth_credential=exchanged,
)
handler = AuthHandler(config)
result = handler.generate_auth_uri()

assert "prompt=none" in result.oauth2.auth_uri

@patch("google.adk.auth.auth_handler.OAuth2Session", MockOAuth2Session)
def test_generate_auth_uri_openid(
Expand Down