adk-docs
adk-docs copied to clipboard
Working example for caching an OAuth credential in the session state
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