From dba525eff95867f16dfb2044f5471efe502894a9 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:11:21 +0000 Subject: [PATCH 1/8] Added docs/_build to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 21e397b..fa1d0dc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist/ src/ .venv .idea +docs/_build/ From d69828b8db29c7d6aeb32045c3b2f5ecf5c21f87 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:16:39 +0000 Subject: [PATCH 2/8] Extended description of OIDC_IDTOKEN_PROCESSING_HOOK --- docs/sections/settings.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/sections/settings.rst b/docs/sections/settings.rst index f8fcbc9..0474b9d 100644 --- a/docs/sections/settings.rst +++ b/docs/sections/settings.rst @@ -96,7 +96,15 @@ OIDC_IDTOKEN_PROCESSING_HOOK ============================ OPTIONAL. ``str``. A string with the location of your function hook. -here you can add extra dictionary values specific for your app into id_token. +Here you can add extra dictionary values specific for your app into id_token. + +The function receives a ``id_token`` dictionary and returns it with additional fields. + +Default is:: + + def default_idtoken_processing_hook(id_token): + + return return id_token OIDC_IDTOKEN_SUB_GENERATOR ========================== From eb7686abba641d024a9c26b90e42d4f441a87c15 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:23:10 +0000 Subject: [PATCH 3/8] added 'user' into default_idtoken_processing_hook --- oidc_provider/lib/utils/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oidc_provider/lib/utils/common.py b/oidc_provider/lib/utils/common.py index c97c7e8..85983e7 100644 --- a/oidc_provider/lib/utils/common.py +++ b/oidc_provider/lib/utils/common.py @@ -49,12 +49,13 @@ def default_after_userlogin_hook(request, user, client): """ return None -def default_idtoken_processing_hook(id_token): +def default_idtoken_processing_hook(id_token, user): """ Hook to perform some additional actions ti `id_token` dictionary just before serialization. :param id_token: dictionary contains values that going to be serialized into `id_token` :type id_token: dict + :param user: user instance :return: custom modified dictionary of values for `id_token` :rtype dict """ From a28db60d9ee1b486b46df75ea934a2fa272f443a Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:24:02 +0000 Subject: [PATCH 4/8] added 'user' into default_idtoken_processing_hook --- oidc_provider/lib/utils/token.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oidc_provider/lib/utils/token.py b/oidc_provider/lib/utils/token.py index 67bfb91..0faa1eb 100644 --- a/oidc_provider/lib/utils/token.py +++ b/oidc_provider/lib/utils/token.py @@ -44,7 +44,7 @@ def create_id_token(user, aud, nonce): if nonce: dic['nonce'] = str(nonce) - dic = settings.get('OIDC_IDTOKEN_PROCESSING_HOOK', import_str=True)(dic) + dic = settings.get('OIDC_IDTOKEN_PROCESSING_HOOK', import_str=True)(dic, user) return dic From 3e772b31618577c5e4f73bc80ebf2f14fa2aedb0 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:25:02 +0000 Subject: [PATCH 5/8] added 'user' into default_idtoken_processing_hook --- docs/sections/settings.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/sections/settings.rst b/docs/sections/settings.rst index 0474b9d..8e2f9e5 100644 --- a/docs/sections/settings.rst +++ b/docs/sections/settings.rst @@ -98,11 +98,12 @@ OIDC_IDTOKEN_PROCESSING_HOOK OPTIONAL. ``str``. A string with the location of your function hook. Here you can add extra dictionary values specific for your app into id_token. -The function receives a ``id_token`` dictionary and returns it with additional fields. +The function receives a ``id_token`` dictionary and ``user`` instance +and returns it with additional fields. Default is:: - def default_idtoken_processing_hook(id_token): + def default_idtoken_processing_hook(id_token, user): return return id_token From 509100f8ad88cc507a65810e056fa08640a15abe Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:28:08 +0000 Subject: [PATCH 6/8] added 'user' into default_idtoken_processing_hook --- oidc_provider/tests/app/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oidc_provider/tests/app/utils.py b/oidc_provider/tests/app/utils.py index a644298..9b76233 100644 --- a/oidc_provider/tests/app/utils.py +++ b/oidc_provider/tests/app/utils.py @@ -108,9 +108,10 @@ def fake_sub_generator(user): return user.email -def fake_idtoken_processing_hook(id_token): +def fake_idtoken_processing_hook(id_token, user): """ Fake function for inserting some keys into token. Testing OIDC_IDTOKEN_PROCESSING_HOOK. """ id_token['test_idtoken_processing_hook'] = FAKE_RANDOM_STRING + id_token['test_idtoken_processing_hook_user_email'] = user.email return id_token From 56ffd92ee84b4c0a66b9c640db9b4da14c9d7537 Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Wed, 17 Feb 2016 22:30:10 +0000 Subject: [PATCH 7/8] added 'user' into default_idtoken_processing_hook --- oidc_provider/tests/test_token_endpoint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/oidc_provider/tests/test_token_endpoint.py b/oidc_provider/tests/test_token_endpoint.py index 0cbc7c3..24e49c2 100644 --- a/oidc_provider/tests/test_token_endpoint.py +++ b/oidc_provider/tests/test_token_endpoint.py @@ -351,3 +351,4 @@ class TokenTestCase(TestCase): id_token = JWT().unpack(response_dic['id_token'].encode('utf-8')).payload() self.assertEqual(id_token.get('test_idtoken_processing_hook'), FAKE_RANDOM_STRING) + self.assertEqual(id_token.get('test_idtoken_processing_hook_user_email'), self.user.email) From 0a2ee70dae58f14179ccfc8b148b2a0167c12b7a Mon Sep 17 00:00:00 2001 From: Wojciech Bartosiak Date: Thu, 18 Feb 2016 13:17:04 +0000 Subject: [PATCH 8/8] Fixed type in return --- docs/sections/settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sections/settings.rst b/docs/sections/settings.rst index 8e2f9e5..f3e4329 100644 --- a/docs/sections/settings.rst +++ b/docs/sections/settings.rst @@ -105,7 +105,7 @@ Default is:: def default_idtoken_processing_hook(id_token, user): - return return id_token + return id_token OIDC_IDTOKEN_SUB_GENERATOR ==========================