|
12 | 12 | from oic import rndstr |
13 | 13 | from oic.oauth2.message import MissingRequiredValue, MissingRequiredAttribute |
14 | 14 | from oic.oic import PREFERENCE2PROVIDER |
15 | | -from oic.oic.message import IdToken, AuthorizationRequest, ClaimsRequest, Claims, EndSessionRequest, EndSessionResponse |
| 15 | +from oic.oic.message import IdToken, ClaimsRequest, Claims, EndSessionRequest, EndSessionResponse |
16 | 16 |
|
| 17 | +from pyop.message import AuthorizationRequest |
17 | 18 | from pyop.access_token import BearerTokenError |
18 | 19 | from pyop.authz_state import AuthorizationState |
19 | 20 | from pyop.client_authentication import InvalidClientAuthentication |
@@ -319,6 +320,19 @@ def test_code_exchange_request(self): |
319 | 320 | self.authn_request_args) |
320 | 321 |
|
321 | 322 | @patch('time.time', MOCK_TIME) |
| 323 | + def test_pkce_code_exchange_request(self): |
| 324 | + self.authorization_code_exchange_request_args['code'] = self.create_authz_code( |
| 325 | + { |
| 326 | + "code_challenge": "_1f8tFjAtu6D1Df-GOyDPoMjCJdEvaSWsnqR6SLpzsw", |
| 327 | + "code_challenge_method": "S256" |
| 328 | + } |
| 329 | + ) |
| 330 | + self.authorization_code_exchange_request_args['code_verifier'] = "SoOEDN-mZKNhw7Mc52VXxyiqTvFB3mod36MwPru253c" |
| 331 | + response = self.provider._do_code_exchange(self.authorization_code_exchange_request_args, None) |
| 332 | + assert response['access_token'] in self.provider.authz_state.access_tokens |
| 333 | + assert_id_token_base_claims(response['id_token'], self.provider.signing_key, self.provider, |
| 334 | + self.authn_request_args) |
| 335 | + @patch('time.time', MOCK_TIME) |
322 | 336 | def test_code_exchange_request_with_claims_requested_in_id_token(self): |
323 | 337 | claims_req = {'claims': ClaimsRequest(id_token=Claims(email=None))} |
324 | 338 | self.authorization_code_exchange_request_args['code'] = self.create_authz_code(extra_auth_req_params=claims_req) |
@@ -374,6 +388,12 @@ def test_handle_token_request_reject_missing_grant_type(self): |
374 | 388 | with pytest.raises(InvalidTokenRequest): |
375 | 389 | self.provider.handle_token_request(urlencode(self.authorization_code_exchange_request_args)) |
376 | 390 |
|
| 391 | + def test_handle_token_request_reject_invalid_code_verifier(self): |
| 392 | + del self.authorization_code_exchange_request_args['grant_type'] |
| 393 | + self.authorization_code_exchange_request_args['code'] = self.create_authz_code() |
| 394 | + with pytest.raises(InvalidTokenRequest): |
| 395 | + self.provider.handle_token_request(urlencode(self.authorization_code_exchange_request_args)) |
| 396 | + |
377 | 397 | def test_refresh_request(self): |
378 | 398 | self.provider.authz_state = AuthorizationState(HashBasedSubjectIdentifierFactory('salt'), |
379 | 399 | refresh_token_lifetime=600) |
|
0 commit comments