|
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 |
| 15 | +from oic.oic.message import IdToken, AuthorizationRequest, ClaimsRequest, Claims, EndSessionRequest, EndSessionResponse |
16 | 16 |
|
17 | 17 | from pyop.access_token import BearerTokenError
|
18 | 18 | from pyop.authz_state import AuthorizationState
|
19 | 19 | from pyop.client_authentication import InvalidClientAuthentication
|
20 | 20 | from pyop.exceptions import InvalidAuthenticationRequest, AuthorizationError, InvalidTokenRequest, \
|
21 |
| - InvalidClientRegistrationRequest, InvalidAccessToken |
| 21 | + InvalidClientRegistrationRequest, InvalidAccessToken, InvalidAuthorizationCode, InvalidSubjectIdentifier |
22 | 22 | from pyop.provider import Provider, redirect_uri_is_in_registered_redirect_uris, \
|
23 | 23 | response_type_is_in_registered_response_types
|
24 | 24 | from pyop.subject_identifier import HashBasedSubjectIdentifierFactory
|
@@ -69,7 +69,9 @@ def inject_provider(request):
|
69 | 69 | 'redirect_uris': [TEST_REDIRECT_URI],
|
70 | 70 | 'response_types': ['code'],
|
71 | 71 | 'client_secret': TEST_CLIENT_SECRET,
|
72 |
| - 'token_endpoint_auth_method': 'client_secret_post' |
| 72 | + 'token_endpoint_auth_method': 'client_secret_post', |
| 73 | + 'post_logout_redirect_uris': ['https://client.example.com/post_logout'] |
| 74 | + |
73 | 75 | }
|
74 | 76 | }
|
75 | 77 |
|
@@ -558,3 +560,58 @@ class TestProviderJWKS(object):
|
558 | 560 | def test_jwks(self):
|
559 | 561 | provider = Provider(rsa_key(), {'issuer': ISSUER}, None, None, None)
|
560 | 562 | assert provider.jwks == {'keys': [provider.signing_key.serialize()]}
|
| 563 | + |
| 564 | + |
| 565 | +@pytest.mark.usefixtures('inject_provider') |
| 566 | +class TestRPInitiatedLogout(object): |
| 567 | + def test_logout_user_with_subject_identifier(self): |
| 568 | + auth_req = AuthorizationRequest(response_type='code id_token token', scope='openid', client_id='client1', |
| 569 | + redirect_uri='https://client.example.com/redirect') |
| 570 | + auth_resp = self.provider.authorize(auth_req, 'user1') |
| 571 | + |
| 572 | + id_token = IdToken().from_jwt(auth_resp['id_token'], key=[self.provider.signing_key]) |
| 573 | + self.provider.logout_user(subject_identifier=id_token['sub']) |
| 574 | + with pytest.raises(InvalidAccessToken): |
| 575 | + self.provider.authz_state.introspect_access_token(auth_resp['access_token']) |
| 576 | + with pytest.raises(InvalidAuthorizationCode): |
| 577 | + self.provider.authz_state.exchange_code_for_token(auth_resp['code']) |
| 578 | + |
| 579 | + def test_logout_user_with_id_token_hint(self): |
| 580 | + auth_req = AuthorizationRequest(response_type='code id_token token', scope='openid', client_id='client1', |
| 581 | + redirect_uri='https://client.example.com/redirect') |
| 582 | + auth_resp = self.provider.authorize(auth_req, 'user1') |
| 583 | + |
| 584 | + self.provider.logout_user(end_session_request=EndSessionRequest(id_token_hint=auth_resp['id_token'])) |
| 585 | + with pytest.raises(InvalidAccessToken): |
| 586 | + self.provider.authz_state.introspect_access_token(auth_resp['access_token']) |
| 587 | + with pytest.raises(InvalidAuthorizationCode): |
| 588 | + self.provider.authz_state.exchange_code_for_token(auth_resp['code']) |
| 589 | + |
| 590 | + def test_logout_user_with_unknown_subject_identifier(self): |
| 591 | + with pytest.raises(InvalidSubjectIdentifier): |
| 592 | + self.provider.logout_user(subject_identifier='unknown') |
| 593 | + |
| 594 | + def test_post_logout_redirect(self): |
| 595 | + auth_req = AuthorizationRequest(response_type='code id_token token', scope='openid', client_id='client1', |
| 596 | + redirect_uri='https://client.example.com/redirect') |
| 597 | + auth_resp = self.provider.authorize(auth_req, 'user1') |
| 598 | + end_session_request = EndSessionRequest(id_token_hint=auth_resp['id_token'], |
| 599 | + post_logout_redirect_uri='https://client.example.com/post_logout', |
| 600 | + state='state') |
| 601 | + redirect_url = self.provider.do_post_logout_redirect(end_session_request) |
| 602 | + assert redirect_url == EndSessionResponse(state='state').request('https://client.example.com/post_logout') |
| 603 | + |
| 604 | + def test_post_logout_redirect_without_post_logout_redirect_uri(self): |
| 605 | + assert self.provider.do_post_logout_redirect(EndSessionRequest()) is None |
| 606 | + |
| 607 | + def test_post_logout_redirect_with_unknown_client_for_post_logout_redirect_uri(self): |
| 608 | + end_session_request = EndSessionRequest(post_logout_redirect_uri='https://client.example.com/post_logout') |
| 609 | + assert self.provider.do_post_logout_redirect(end_session_request) is None |
| 610 | + |
| 611 | + def test_post_logout_redirect_with_unknown_post_logout_redirect_uri(self): |
| 612 | + auth_req = AuthorizationRequest(response_type='code id_token token', scope='openid', client_id='client1', |
| 613 | + redirect_uri='https://client.example.com/redirect') |
| 614 | + auth_resp = self.provider.authorize(auth_req, 'user1') |
| 615 | + end_session_request = EndSessionRequest(id_token_hint=auth_resp['id_token'], |
| 616 | + post_logout_redirect_uri='https://client.example.com/unknown') |
| 617 | + assert self.provider.do_post_logout_redirect(end_session_request) is None |
0 commit comments