@@ -147,44 +147,46 @@ def verify_signed_jwt_with_certs(jwt, certs, audience):
147
147
signature = _urlsafe_b64decode (signature )
148
148
149
149
# Parse token.
150
- json_body = _urlsafe_b64decode (payload )
150
+ payload_bytes = _urlsafe_b64decode (payload )
151
151
try :
152
- parsed = json .loads (_from_bytes (json_body ))
152
+ payload_dict = json .loads (_from_bytes (payload_bytes ))
153
153
except :
154
- raise AppIdentityError ('Can\' t parse token: %s' % json_body )
154
+ raise AppIdentityError ('Can\' t parse token: %s' % ( payload_bytes ,) )
155
155
156
156
# Check signature.
157
157
_verify_signature (message_to_sign , signature , certs )
158
158
159
159
# 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
164
164
165
165
# Check expiration timestamp.
166
166
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
173
174
174
175
if now < earliest :
175
176
raise AppIdentityError ('Token used too early, %d < %d: %s' %
176
- (now , earliest , json_body ))
177
+ (now , earliest , payload_bytes ))
177
178
if now > latest :
178
179
raise AppIdentityError ('Token used too late, %d > %d: %s' %
179
- (now , latest , json_body ))
180
+ (now , latest , payload_bytes ))
180
181
181
182
# Check audience.
182
183
if audience is not None :
183
- aud = parsed .get ('aud' )
184
+ aud = payload_dict .get ('aud' )
184
185
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 ,))
186
188
if aud != audience :
187
189
raise AppIdentityError ('Wrong recipient, %s != %s: %s' %
188
- (aud , audience , json_body ))
190
+ (aud , audience , payload_bytes ))
189
191
190
- return parsed
192
+ return payload_dict
0 commit comments