Skip to content

Commit fc2d063

Browse files
committed
Using more descriptive names for JWT parts.
Previous variables in verify_signed_jwt_with_certs did not illustrate the actual use of each part.
1 parent 56957e1 commit fc2d063

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

oauth2client/crypt.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,44 +147,46 @@ def verify_signed_jwt_with_certs(jwt, certs, audience):
147147
signature = _urlsafe_b64decode(signature)
148148

149149
# Parse token.
150-
json_body = _urlsafe_b64decode(payload)
150+
payload_bytes = _urlsafe_b64decode(payload)
151151
try:
152-
parsed = json.loads(_from_bytes(json_body))
152+
payload_dict = json.loads(_from_bytes(payload_bytes))
153153
except:
154-
raise AppIdentityError('Can\'t parse token: %s' % json_body)
154+
raise AppIdentityError('Can\'t parse token: %s' % (payload_bytes,))
155155

156156
# Check signature.
157157
_verify_signature(message_to_sign, signature, certs)
158158

159159
# Check creation timestamp.
160-
iat = parsed.get('iat')
161-
if iat is None:
162-
raise AppIdentityError('No iat field in token: %s' % json_body)
163-
earliest = iat - CLOCK_SKEW_SECS
160+
issued_at = payload_dict.get('iat')
161+
if issued_at is None:
162+
raise AppIdentityError('No iat field in token: %s' % (payload_bytes,))
163+
earliest = issued_at - CLOCK_SKEW_SECS
164164

165165
# Check expiration timestamp.
166166
now = int(time.time())
167-
exp = parsed.get('exp')
168-
if exp is None:
169-
raise AppIdentityError('No exp field in token: %s' % json_body)
170-
if exp >= now + MAX_TOKEN_LIFETIME_SECS:
171-
raise AppIdentityError('exp field too far in future: %s' % json_body)
172-
latest = exp + CLOCK_SKEW_SECS
167+
expiration = payload_dict.get('exp')
168+
if expiration is None:
169+
raise AppIdentityError('No exp field in token: %s' % (payload_bytes,))
170+
if expiration >= now + MAX_TOKEN_LIFETIME_SECS:
171+
raise AppIdentityError('exp field too far in future: %s' %
172+
(payload_bytes,))
173+
latest = expiration + CLOCK_SKEW_SECS
173174

174175
if now < earliest:
175176
raise AppIdentityError('Token used too early, %d < %d: %s' %
176-
(now, earliest, json_body))
177+
(now, earliest, payload_bytes))
177178
if now > latest:
178179
raise AppIdentityError('Token used too late, %d > %d: %s' %
179-
(now, latest, json_body))
180+
(now, latest, payload_bytes))
180181

181182
# Check audience.
182183
if audience is not None:
183-
aud = parsed.get('aud')
184+
aud = payload_dict.get('aud')
184185
if aud is None:
185-
raise AppIdentityError('No aud field in token: %s' % json_body)
186+
raise AppIdentityError('No aud field in token: %s' %
187+
(payload_bytes,))
186188
if aud != audience:
187189
raise AppIdentityError('Wrong recipient, %s != %s: %s' %
188-
(aud, audience, json_body))
190+
(aud, audience, payload_bytes))
189191

190-
return parsed
192+
return payload_dict

0 commit comments

Comments
 (0)