|
5 | 5 | from importlib import import_module |
6 | 6 |
|
7 | 7 | from cryptojwt.utils import as_bytes |
8 | | -from oidcmsg.oauth2 import is_error_message |
9 | 8 | from oidcmsg.oauth2 import ResponseMessage |
| 9 | +from oidcmsg.oauth2 import is_error_message |
10 | 10 | from oidcmsg.oidc import AccessTokenResponse |
11 | 11 | from oidcmsg.oidc import AuthorizationRequest |
12 | 12 | from oidcmsg.oidc import AuthorizationResponse |
13 | 13 | from oidcmsg.oidc import OpenIDSchema |
14 | 14 | from oidcmsg.time_util import time_sans_frac |
15 | 15 | from oidcservice import rndstr |
16 | 16 | from oidcservice.exception import OidcServiceError |
17 | | -from oidcservice.state_interface import StateInterface |
18 | 17 | from oidcservice.state_interface import InMemoryStateDataBase |
| 18 | +from oidcservice.state_interface import StateInterface |
19 | 19 |
|
20 | 20 | from oidcrp import oauth2 |
21 | 21 | from oidcrp import oidc |
@@ -329,7 +329,21 @@ def client_setup(self, iss_id='', user=''): |
329 | 329 | return client |
330 | 330 |
|
331 | 331 | issuer = self.do_provider_info(client) |
332 | | - self.do_client_registration(client, iss_id) |
| 332 | + _sc = client.service_context |
| 333 | + try: |
| 334 | + _fe = _sc.federation_entity |
| 335 | + except AttributeError: |
| 336 | + _fe = None |
| 337 | + registration_type = 'explicit' |
| 338 | + else: |
| 339 | + registration_type = _fe.registration_type |
| 340 | + |
| 341 | + if registration_type == 'implicit': |
| 342 | + _sc.client_id = client.client_id = _fe.entity_id |
| 343 | + _sc.redirect_uris = _sc.behaviour['redirect_uris'] |
| 344 | + else: |
| 345 | + self.do_client_registration(client, iss_id) |
| 346 | + |
333 | 347 | self.issuer2rp[issuer] = client |
334 | 348 | return client |
335 | 349 |
|
@@ -805,6 +819,39 @@ def get_valid_access_token(self, state): |
805 | 819 | else: |
806 | 820 | raise OidcServiceError('No valid access token') |
807 | 821 |
|
| 822 | + def logout(self, state, client=None, post_logout_redirect_uri=''): |
| 823 | + """ |
| 824 | + Does a RP initiated logout from an OP. After logout the user will be |
| 825 | + redirect by the OP to a URL of choice (post_logout_redirect_uri). |
| 826 | +
|
| 827 | + :param state: Key to an active session |
| 828 | + :param client: Which client to use |
| 829 | + :param post_logout_redirect_uri: If a special post_logout_redirect_uri |
| 830 | + should be used |
| 831 | + :return: |
| 832 | + """ |
| 833 | + if client is None: |
| 834 | + client = self.get_client_from_session_key(state) |
| 835 | + |
| 836 | + try: |
| 837 | + srv = client.service['end_session'] |
| 838 | + except KeyError: |
| 839 | + raise OidcServiceError("Does not know how to logout") |
| 840 | + |
| 841 | + if post_logout_redirect_uri: |
| 842 | + request_args = { |
| 843 | + "post_logout_redirect_uri": post_logout_redirect_uri |
| 844 | + } |
| 845 | + else: |
| 846 | + request_args = {} |
| 847 | + |
| 848 | + resp = client.do_request('end_session', state=state, |
| 849 | + request_args=request_args) |
| 850 | + if is_error_message(resp): |
| 851 | + raise OidcServiceError(resp['error']) |
| 852 | + |
| 853 | + return resp |
| 854 | + |
808 | 855 |
|
809 | 856 | def get_provider_specific_service(service_provider, service, **kwargs): |
810 | 857 | """ |
|
0 commit comments