Skip to content

Commit 1c92a00

Browse files
committed
exp, iat and client_id_issued_at should be integers
1 parent 8fdf563 commit 1c92a00

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/pyop/authz_state.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def create_authorization_code(self, authorization_request, subject_identifier, s
9595
authorization_code = rand_str()
9696
authz_info = {
9797
'used': False,
98-
'exp': time.time() + self.authorization_code_lifetime,
98+
'exp': int(time.time()) + self.authorization_code_lifetime,
9999
'sub': subject_identifier,
100100
'granted_scope': scope,
101101
self.KEY_AUTHORIZATION_REQUEST: authorization_request.to_dict()
@@ -129,8 +129,8 @@ def _create_access_token(self, subject_identifier, auth_req, granted_scope, curr
129129
logger.debug('creating access token for scope=%s', scope)
130130

131131
authz_info = {
132-
'iat': time.time(),
133-
'exp': time.time() + self.access_token_lifetime,
132+
'iat': int(time.time()),
133+
'exp': int(time.time()) + self.access_token_lifetime,
134134
'sub': subject_identifier,
135135
'client_id': auth_req['client_id'],
136136
'aud': [auth_req['client_id']],
@@ -157,9 +157,9 @@ def exchange_code_for_token(self, authorization_code):
157157
if authz_info['used']:
158158
logger.debug('detected already used authz_code=%s', authorization_code)
159159
raise InvalidAuthorizationCode('{} has already been used'.format(authorization_code))
160-
elif authz_info['exp'] < time.time():
160+
elif authz_info['exp'] < int(time.time()):
161161
logger.debug('detected expired authz_code=%s, now=%s > exp=%s ',
162-
authorization_code, time.time(), authz_info['exp'])
162+
authorization_code, int(time.time()), authz_info['exp'])
163163
raise InvalidAuthorizationCode('{} has expired'.format(authorization_code))
164164

165165
authz_info['used'] = True
@@ -181,7 +181,7 @@ def introspect_access_token(self, access_token_value):
181181

182182
authz_info = self.access_tokens[access_token_value]
183183

184-
introspection = {'active': authz_info['exp'] >= time.time()}
184+
introspection = {'active': authz_info['exp'] >= int(time.time())}
185185

186186
introspection_params = {k: v for k, v in authz_info.items() if k in TokenIntrospectionResponse.c_param}
187187
introspection.update(introspection_params)
@@ -200,7 +200,7 @@ def create_refresh_token(self, access_token_value):
200200
return None
201201

202202
refresh_token = rand_str()
203-
authz_info = {'access_token': access_token_value, 'exp': time.time() + self.refresh_token_lifetime}
203+
authz_info = {'access_token': access_token_value, 'exp': int(time.time()) + self.refresh_token_lifetime}
204204
self.refresh_tokens[refresh_token] = authz_info
205205

206206
logger.debug('issued refresh_token=%s expiring=%d for access_token=%s', refresh_token, authz_info['exp'],
@@ -218,7 +218,7 @@ def use_refresh_token(self, refresh_token, scope=None):
218218
raise InvalidRefreshToken('{} unknown'.format(refresh_token))
219219

220220
refresh_token_info = self.refresh_tokens[refresh_token]
221-
if 'exp' in refresh_token_info and refresh_token_info['exp'] < time.time():
221+
if 'exp' in refresh_token_info and refresh_token_info['exp'] < int(time.time()):
222222
raise InvalidRefreshToken('{} has expired'.format(refresh_token))
223223

224224
authz_info = self.access_tokens[refresh_token_info['access_token']]
@@ -240,7 +240,7 @@ def use_refresh_token(self, refresh_token, scope=None):
240240
new_refresh_token = None
241241
if self.refresh_token_threshold \
242242
and 'exp' in refresh_token_info \
243-
and refresh_token_info['exp'] - time.time() < self.refresh_token_threshold:
243+
and refresh_token_info['exp'] - int(time.time()) < self.refresh_token_threshold:
244244
# refresh token is close to expiry, issue a new one
245245
new_refresh_token = self.create_refresh_token(new_access_token.value)
246246
else:

src/pyop/provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ def _create_signed_id_token(self,
263263
id_token = IdToken(iss=self.configuration_information['issuer'],
264264
sub=sub,
265265
aud=client_id,
266-
iat=time.time(),
267-
exp=time.time() + self.id_token_lifetime,
266+
iat=int(time.time()),
267+
exp=int(time.time()) + self.id_token_lifetime,
268268
**args)
269269

270270
if nonce:
@@ -488,7 +488,7 @@ def handle_client_registration_request(self, request, http_headers=None):
488488
client_id, client_secret = self._issue_new_client()
489489
credentials = {
490490
'client_id': client_id,
491-
'client_id_issued_at': time.time(),
491+
'client_id_issued_at': int(time.time()),
492492
'client_secret': client_secret,
493493
'client_secret_expires_at': 0 # never expires
494494
}

tests/pyop/test_authz_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_create_authorization_code(self, authorization_state_factory, authorizat
6565

6666
authz_code = authorization_state.create_authorization_code(authorization_request, self.TEST_SUBJECT_IDENTIFIER)
6767
assert authz_code in authorization_state.authorization_codes
68-
assert authorization_state.authorization_codes[authz_code]['exp'] == time.time() + code_lifetime
68+
assert authorization_state.authorization_codes[authz_code]['exp'] == int(time.time()) + code_lifetime
6969
assert authorization_state.authorization_codes[authz_code]['used'] is False
7070
assert authorization_state.authorization_codes[authz_code][AuthorizationState.KEY_AUTHORIZATION_REQUEST] == \
7171
authorization_request.to_dict()
@@ -223,7 +223,7 @@ def test_create_refresh_token_with_expiration_time(self, authorization_state_fac
223223

224224
assert refresh_token in authorization_state.refresh_tokens
225225
assert authorization_state.refresh_tokens[refresh_token]['access_token'] == access_token.value
226-
assert authorization_state.refresh_tokens[refresh_token]['exp'] == time.time() + refresh_token_lifetime
226+
assert authorization_state.refresh_tokens[refresh_token]['exp'] == int(time.time()) + refresh_token_lifetime
227227

228228
def test_use_refresh_token(self, authorization_state_factory, authorization_request):
229229
authorization_state = authorization_state_factory(access_token_lifetime=self.TEST_TOKEN_LIFETIME,
@@ -267,7 +267,7 @@ def test_use_refresh_token_issues_new_refresh_token_if_the_old_is_close_to_expir
267267
old_access_token = authorization_state.create_access_token(authorization_request, self.TEST_SUBJECT_IDENTIFIER)
268268
refresh_token = authorization_state.create_refresh_token(old_access_token.value)
269269

270-
close_to_expiration = time.time() + authorization_state.refresh_token_lifetime - 50
270+
close_to_expiration = int(time.time()) + authorization_state.refresh_token_lifetime - 50
271271
with patch('time.time', Mock(return_value=close_to_expiration)):
272272
new_access_token, new_refresh_token = authorization_state.use_refresh_token(refresh_token)
273273

tests/pyop/test_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def test_refresh_request_with_refresh_token_close_to_expiry_issues_new_refresh_t
388388
refresh_token_threshold=2)
389389
self.refresh_token_request_args['refresh_token'] = self.create_refresh_token()
390390

391-
close_to_expiration = time.time() + self.provider.authz_state.refresh_token_lifetime - 1
391+
close_to_expiration = int(time.time()) + self.provider.authz_state.refresh_token_lifetime - 1
392392
with patch('time.time', Mock(return_value=close_to_expiration)):
393393
response = self.provider.handle_token_request(urlencode(self.refresh_token_request_args))
394394
assert response['access_token'] in self.provider.authz_state.access_tokens

0 commit comments

Comments
 (0)