From 9ddbdbf294b17fa833097d240e550910707f57cd Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Fri, 31 Mar 2017 13:00:24 +0100 Subject: [PATCH 1/2] rename OIDC_POST_END_SESSION_HOOK to OIDC_AFTER_END_SESSION_HOOK --- CHANGELOG.md | 2 +- oidc_provider/lib/utils/common.py | 4 ++-- oidc_provider/settings.py | 4 ++-- oidc_provider/tests/test_end_session_endpoint.py | 6 +++--- oidc_provider/views.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f687d32..8364258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. ##### Added - Signals when user accept/decline the authorization page. -- `OIDC_POST_END_SESSION_HOOK` setting for additional bussiness logic +- `OIDC_AFTER_END_SESSION_HOOK` setting for additional business logic - Feature granttype password ##### Fixed diff --git a/oidc_provider/lib/utils/common.py b/oidc_provider/lib/utils/common.py index 52bb962..1a69deb 100644 --- a/oidc_provider/lib/utils/common.py +++ b/oidc_provider/lib/utils/common.py @@ -85,9 +85,9 @@ def default_after_userlogin_hook(request, user, client): return None -def default_post_end_session_hook(request, id_token=None, post_logout_redirect_uri=None, state=None, client=None, next_page=None): +def default_after_end_session_hook(request, id_token=None, post_logout_redirect_uri=None, state=None, client=None, next_page=None): """ - Default function for setting OIDC_POST_END_SESSION_HOOK. + Default function for setting OIDC_AFTER_END_SESSION_HOOK. :param request: Django request object :type request: django.http.HttpRequest diff --git a/oidc_provider/settings.py b/oidc_provider/settings.py index c6de458..3421d1b 100644 --- a/oidc_provider/settings.py +++ b/oidc_provider/settings.py @@ -31,12 +31,12 @@ class DefaultSettings(object): return 'oidc_provider.lib.utils.common.default_after_userlogin_hook' @property - def OIDC_POST_END_SESSION_HOOK(self): + def OIDC_AFTER_END_SESSION_HOOK(self): """ OPTIONAL. Provide a way to plug into the end session process just before calling Django's logout function, typically to perform some business logic. """ - return 'oidc_provider.lib.utils.common.default_post_end_session_hook' + return 'oidc_provider.lib.utils.common.default_after_end_session_hook' @property def OIDC_CODE_EXPIRE(self): diff --git a/oidc_provider/tests/test_end_session_endpoint.py b/oidc_provider/tests/test_end_session_endpoint.py index 6982704..89f0d8c 100644 --- a/oidc_provider/tests/test_end_session_endpoint.py +++ b/oidc_provider/tests/test_end_session_endpoint.py @@ -46,9 +46,9 @@ class EndSessionTestCase(TestCase): response = self.client.get(self.url, query_params) self.assertRedirects(response, self.LOGOUT_URL, fetch_redirect_response=False) - @mock.patch(settings.get('OIDC_POST_END_SESSION_HOOK')) + @mock.patch(settings.get('OIDC_AFTER_END_SESSION_HOOK')) def test_call_post_end_session_hook(self, hook_function): self.client.get(self.url) - self.assertTrue(hook_function.called, 'OIDC_POST_END_SESSION_HOOK should be called') - self.assertTrue(hook_function.call_count == 1, 'OIDC_POST_END_SESSION_HOOK should be called once but was {}'.format(hook_function.call_count)) + self.assertTrue(hook_function.called, 'OIDC_AFTER_END_SESSION_HOOK should be called') + self.assertTrue(hook_function.call_count == 1, 'OIDC_AFTER_END_SESSION_HOOK should be called once but was {}'.format(hook_function.call_count)) diff --git a/oidc_provider/views.py b/oidc_provider/views.py index c2e8cb7..b2c4d80 100644 --- a/oidc_provider/views.py +++ b/oidc_provider/views.py @@ -269,7 +269,7 @@ class EndSessionView(View): client = None next_page = settings.get('LOGIN_URL') - post_end_session_hook = settings.get('OIDC_POST_END_SESSION_HOOK', import_str=True) + after_end_session_hook = settings.get('OIDC_AFTER_END_SESSION_HOOK', import_str=True) if id_token_hint: client_id = client_id_from_id_token(id_token_hint) @@ -287,7 +287,7 @@ class EndSessionView(View): except Client.DoesNotExist: pass - post_end_session_hook( + after_end_session_hook( request=request, id_token=id_token_hint, post_logout_redirect_uri=post_logout_redirect_uri, From ca98c33a7d61382410e1e702e0df82120e99f809 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Fri, 31 Mar 2017 13:00:33 +0100 Subject: [PATCH 2/2] added docs for OIDC_AFTER_END_SESSION_HOOK --- docs/sections/settings.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/sections/settings.rst b/docs/sections/settings.rst index 667157c..80480f1 100644 --- a/docs/sections/settings.rst +++ b/docs/sections/settings.rst @@ -36,6 +36,18 @@ Return ``None`` if you want to continue with the flow. The typical situation will be checking some state of the user or maybe redirect him somewhere. With request you have access to all OIDC parameters. Remember that if you redirect the user to another place then you need to take him back to the authorize endpoint (use ``request.get_full_path()`` as the value for a "next" parameter). +OIDC_AFTER_END_SESSION_HOOK +=========================== + +OPTIONAL. ``str``. A string with the location of your function. Provide a way to plug into the log out process just before calling Django's log out function, typically to perform some business logic. + +Default is:: + + def default_after_end_session_hook(request, id_token=None, post_logout_redirect_uri=None, state=None, client=None, next_page=None): + return None + +Return ``None`` if you want to continue with the flow. + OIDC_CODE_EXPIRE ================