Skip to content

fix: fix token clock skew issue #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion packages/toolbox-core/src/toolbox_core/auth_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def _update_cache(new_token: str) -> None:
# verify_oauth2_token not only decodes but also validates the token's
# signature and claims against Google's public keys.
# It's a synchronous, CPU-bound operation, safe for async contexts.
claims = id_token.verify_oauth2_token(new_token, Request())
claims = id_token.verify_oauth2_token(
new_token, Request(), clock_skew_in_seconds=60
)

expiry_timestamp = claims.get("exp")
if not expiry_timestamp:
Expand Down
4 changes: 3 additions & 1 deletion packages/toolbox-core/tests/test_auth_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def test_get_google_id_token_success_local_creds(
mock_default.assert_called_once_with()
mock_session.assert_called_once_with(mock_creds)
mock_creds.refresh.assert_called_once_with(mock_request_instance)
mock_verify.assert_called_once_with(MOCK_ID_TOKEN, ANY)
mock_verify.assert_called_once_with(
MOCK_ID_TOKEN, ANY, clock_skew_in_seconds=60
)
assert token == f"{auth_methods.BEARER_TOKEN_PREFIX}{MOCK_ID_TOKEN}"
assert auth_methods._token_cache["token"] == MOCK_ID_TOKEN
assert auth_methods._token_cache["expires_at"] == MOCK_EXPIRY_DATETIME
Expand Down