adk-docs icon indicating copy to clipboard operation
adk-docs copied to clipboard

Working example for caching an OAuth credential in the session state

Open pgentile opened this issue 3 months ago • 0 comments

If the expiry is not saved in credentials, we are not able to rebuild a valid token from the state of the session. So we have compute the expiry date of the token and set it in the credentials.

No expiry in credentials:

cached = json.loads(creds.to_json())
creds = Credentials.from_authorized_user_info(cached_token_info, SCOPES)
assert creds.valid == False
assert creds.expired == True

Expiry in credentials:

cached = json.loads(creds.to_json())
creds = Credentials.from_authorized_user_info(cached_token_info, SCOPES)
assert creds.valid == True
assert creds.expired == False

pgentile avatar Sep 02 '25 16:09 pgentile