Skip to content

Commit 3cc3f16

Browse files
fix: invalid expiry type (#481)
1 parent a729f9b commit 3cc3f16

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/google-auth/google/auth/compute_engine/credentials.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ def _call_metadata_identity_endpoint(self, request):
274274
request (google.auth.transport.Request): The object used to make
275275
HTTP requests.
276276
277+
Returns:
278+
Tuple[str, datetime.datetime]: The ID token and the expiry of the ID token.
279+
277280
Raises:
278281
google.auth.exceptions.RefreshError: If the Compute Engine metadata
279282
service can't be reached or if the instance has no credentials.
@@ -291,7 +294,7 @@ def _call_metadata_identity_endpoint(self, request):
291294
six.raise_from(new_exc, caught_exc)
292295

293296
_, payload, _, _ = jwt._unverified_decode(id_token)
294-
return id_token, payload["exp"]
297+
return id_token, datetime.datetime.fromtimestamp(payload["exp"])
295298

296299
def refresh(self, request):
297300
"""Refreshes the ID token.

packages/google-auth/system_tests/test_compute_engine.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from datetime import datetime
16+
1517
import pytest
1618

1719
import google.auth
@@ -61,8 +63,9 @@ def test_id_token_from_metadata(http_request):
6163
credentials.refresh(http_request)
6264

6365
_, payload, _, _ = jwt._unverified_decode(credentials.token)
66+
assert credentials.valid
6467
assert payload["aud"] == AUDIENCE
65-
assert payload["exp"] == credentials.expiry
68+
assert datetime.fromtimestamp(payload["exp"]) == credentials.expiry
6669

6770

6871
def test_fetch_id_token(http_request):

packages/google-auth/tests/compute_engine/test_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def test_get_id_token_from_metadata(self, get, get_service_account_info):
522522
cred.refresh(request=mock.Mock())
523523

524524
assert cred.token == SAMPLE_ID_TOKEN
525-
assert cred.expiry == SAMPLE_ID_TOKEN_EXP
525+
assert cred.expiry == datetime.datetime.fromtimestamp(SAMPLE_ID_TOKEN_EXP)
526526
assert cred._use_metadata_identity_endpoint
527527
assert cred._signer is None
528528
assert cred._token_uri is None

0 commit comments

Comments
 (0)