Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/tools/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ else:
* This returns the updated `exchanged_credential` object sent back by the client (containing the callback URL in `auth_response_uri`).

```py
from datetime import datetime, timedelta

# Use auth_scheme and auth_credential configured in the tool.
# exchanged_credential: AuthCredential | None

Expand All @@ -459,9 +461,11 @@ if exchanged_credential:
# ADK exchanged the access token already for us
access_token = exchanged_credential.oauth2.access_token
refresh_token = exchanged_credential.oauth2.refresh_token
expiry = datetime.utcnow() + timedelta(seconds=exchanged_credential.oauth2.expires_in) if exchanged_credential.oauth2.expires_in else None
creds = Credentials(
token=access_token,
refresh_token=refresh_token,
expiry=expiry,
token_uri=auth_scheme.flows.authorizationCode.tokenUrl,
client_id=auth_credential.oauth2.client_id,
client_secret=auth_credential.oauth2.client_secret,
Expand Down