Update id_token on refresh

This commit is contained in:
Dan Ring
2015-11-12 15:05:58 -08:00
parent ab3e5353bf
commit c53636ed36
2 changed files with 25 additions and 0 deletions

View File

@@ -883,6 +883,10 @@ class OAuth2Credentials(Credentials):
seconds=int(d['expires_in'])) + datetime.datetime.utcnow()
else:
self.token_expiry = None
if 'id_token' in d:
self.id_token = _extract_id_token(d['id_token'])
else:
self.id_token = None
# On temporary refresh errors, the user does not actually have to
# re-authorize, so we unflag here.
self.invalid = False

View File

@@ -886,6 +886,27 @@ class BasicCredentialsTests(unittest.TestCase):
self.credentials.retrieve_scopes,
http)
def test_refresh_updates_id_token(self):
for status_code in REFRESH_STATUS_CODES:
body = {'foo': 'bar'}
body_json = json.dumps(body).encode('ascii')
payload = base64.urlsafe_b64encode(body_json).strip(b'=')
jwt = b'stuff.' + payload + b'.signature'
token_response = (b'{'
b' "access_token":"1/3w",'
b' "expires_in":3600,'
b' "id_token": "' + jwt + b'"'
b'}')
http = HttpMockSequence([
({'status': status_code}, b''),
({'status': '200'}, token_response),
({'status': '200'}, 'echo_request_headers'),
])
http = self.credentials.authorize(http)
resp, content = http.request('http://example.com')
self.assertEqual(self.credentials.id_token, body)
class AccessTokenCredentialsTests(unittest.TestCase):