Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 1cba0f8

Browse files
author
Jon Wayne Parrott
authored
Fix App Engine's expiration calculation (#197)
1 parent 4460a96 commit 1cba0f8

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

google/auth/app_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def refresh(self, request):
114114
# pylint: disable=unused-argument
115115
token, ttl = app_identity.get_access_token(
116116
self._scopes, self._service_account_id)
117-
expiry = _helpers.utcnow() + datetime.timedelta(seconds=ttl)
117+
expiry = datetime.datetime.utcfromtimestamp(ttl)
118118

119119
self.token, self.expiry = token, expiry
120120

tests/test_app_engine.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import mock
1818
import pytest
1919

20-
from google.auth import _helpers
2120
from google.auth import app_engine
2221

2322

@@ -134,7 +133,7 @@ def test_service_account_email_explicit(self, app_identity):
134133
return_value=datetime.datetime.min)
135134
def test_refresh(self, utcnow, app_identity):
136135
token = 'token'
137-
ttl = _helpers.CLOCK_SKEW_SECS + 100
136+
ttl = 643942923
138137
app_identity.get_access_token.return_value = token, ttl
139138
credentials = app_engine.Credentials(scopes=['email'])
140139

@@ -143,8 +142,8 @@ def test_refresh(self, utcnow, app_identity):
143142
app_identity.get_access_token.assert_called_with(
144143
credentials.scopes, credentials._service_account_id)
145144
assert credentials.token == token
146-
assert credentials.expiry == (
147-
utcnow() + datetime.timedelta(seconds=ttl))
145+
assert credentials.expiry == datetime.datetime(
146+
1990, 5, 29, 1, 2, 3)
148147
assert credentials.valid
149148
assert not credentials.expired
150149

0 commit comments

Comments
 (0)