Merge pull request #81 from wojtek-fliposports/v0.2.x
Add user into OIDC_IDTOKEN_PROCESSING_HOOK function. Fix documentation.
This commit is contained in:
commit
b0cb34e6f3
6 changed files with 17 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ dist/
|
|||
src/
|
||||
.venv
|
||||
.idea
|
||||
docs/_build/
|
||||
|
|
|
@ -96,7 +96,16 @@ 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 ``user`` instance
|
||||
and returns it with additional fields.
|
||||
|
||||
Default is::
|
||||
|
||||
def default_idtoken_processing_hook(id_token, user):
|
||||
|
||||
return id_token
|
||||
|
||||
OIDC_IDTOKEN_SUB_GENERATOR
|
||||
==========================
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue