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

Commit 23a4e63

Browse files
authored
Update local oauth path to use v3 tokeninfo api (#159)
1 parent 953765f commit 23a4e63

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

endpoints/test/users_id_token_test.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,19 @@ class UsersIdTokenTestBase(unittest.TestCase):
142142
_SAMPLE_TIME_NOW = 1360964700
143143
_SAMPLE_OAUTH_SCOPES = ['https://www.googleapis.com/auth/userinfo.email']
144144
_SAMPLE_OAUTH_TOKEN_INFO = {
145-
'issued_to': ('919214422084-c0jrodnkm7ntttjhhttilqjq5d7l7mu5.apps.'
146-
'googleusercontent.com'),
147-
'user_id': '108495933693426793887',
148-
'expires_in': 3384,
149145
'access_type': 'online',
150-
'audience': ('919214422084-c0jrodnkm7ntttjhhttilqjq5d7l7mu5.apps.'
146+
'aud': ('919214422084-c0jrodnkm7ntttjhhttilqjq5d7l7mu5.apps.'
147+
'googleusercontent.com'),
148+
'azp': ('919214422084-c0jrodnkm7ntttjhhttilqjq5d7l7mu5.apps.'
151149
'googleusercontent.com'),
150+
'email': 'kevind@gmail.com',
151+
'email_verified': 'true',
152+
'exp': str(_SAMPLE_TIME_NOW + 3384),
153+
'expires_in': 3384,
152154
'scope': (
153155
'https://www.googleapis.com/auth/userinfo.profile '
154156
'https://www.googleapis.com/auth/userinfo.email'),
155-
'email': 'kevind@gmail.com',
156-
'verified_email': True
157+
'sub': '108495933693426793887',
157158
}
158159

159160
def setUp(self):
@@ -431,7 +432,7 @@ class DummyResponse(object):
431432
status_code = 200
432433
content = json.dumps(token)
433434

434-
expected_uri = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=unused_token'
435+
expected_uri = 'https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=unused_token'
435436
with mock.patch.object(urlfetch, 'fetch') as mock_fetch:
436437
mock_fetch.return_value = DummyResponse()
437438
users_id_token._set_bearer_user_vars_local(
@@ -454,10 +455,10 @@ def assertOauthLocalFailed(self, token_update):
454455
self.assertNotIn('ENDPOINTS_AUTH_DOMAIN', os.environ)
455456

456457
def testOauthLocalBadEmail(self):
457-
self.assertOauthLocalFailed({'verified_email': False})
458+
self.assertOauthLocalFailed({'email_verified': 'false'})
458459

459460
def testOauthLocalBadClientId(self):
460-
self.assertOauthLocalFailed({'issued_to': 'abc.appspot.com'})
461+
self.assertOauthLocalFailed({'azp': 'abc.appspot.com'})
461462

462463
def testOauthLocalBadScopes(self):
463464
self.assertOauthLocalFailed({'scope': 'useless_scope and_another'})

endpoints/users_id_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
_ENV_AUTH_EMAIL = 'ENDPOINTS_AUTH_EMAIL'
7474
_ENV_AUTH_DOMAIN = 'ENDPOINTS_AUTH_DOMAIN'
7575
_EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'
76-
_TOKENINFO_URL = 'https://www.googleapis.com/oauth2/v1/tokeninfo'
76+
_TOKENINFO_URL = 'https://www.googleapis.com/oauth2/v3/tokeninfo'
7777
_MAX_AGE_REGEX = re.compile(r'\s*max-age\s*=\s*(\d+)\s*')
7878
_CERT_NAMESPACE = '__verify_jwt'
7979
_ISSUERS = ('accounts.google.com', 'https://accounts.google.com')
@@ -417,12 +417,12 @@ def _set_bearer_user_vars_local(token, allowed_client_ids, scopes):
417417
if 'email' not in token_info:
418418
_logger.warning('Oauth token doesn\'t include an email address.')
419419
return
420-
if not token_info.get('verified_email'):
420+
if token_info.get('email_verified') != 'true':
421421
_logger.warning('Oauth token email isn\'t verified.')
422422
return
423423

424424
# Validate client ID.
425-
client_id = token_info.get('issued_to')
425+
client_id = token_info.get('azp')
426426
if (list(allowed_client_ids) != SKIP_CLIENT_ID_CHECK and
427427
client_id not in allowed_client_ids):
428428
_logger.warning('Client ID is not allowed: %s', client_id)

0 commit comments

Comments
 (0)