Skip to content

Commit 21f74c7

Browse files
Merge pull request #2 from safarijv/DOM-1132
DOM-1132 | Add setting to allow overidding create_id_token
2 parents 1877e42 + a171d47 commit 21f74c7

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ All notable changes to this project will be documented in this file.
55
### [Unreleased]
66

77

8+
### [0.5.5] - 2018-09-11
9+
10+
##### Changed
11+
- Added `OIDC_IDTOKEN_CREATE_HOOK` setting to allow for setting function that's used when creating the payload dict for the id_token.
12+
13+
814
### [0.5.2] - 2017-08-22
915

1016
##### Fixed
1117
- Fix infinite login loop if "prompt=login" (#198)
12-
- Fix Django 2.0 deprecation warnings (#185)
18+
- Fix Django 2.0 deprecation warnings (#185)
1319

1420

1521
### [0.5.1] - 2017-07-11

oidc_provider/lib/endpoints/authorize.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
)
2222
from oidc_provider.lib.utils.token import (
2323
create_code,
24-
create_id_token,
2524
create_token,
2625
encode_id_token,
2726
)
@@ -162,7 +161,11 @@ def create_response_uri(self):
162161
# Include at_hash when access_token is being returned.
163162
if 'access_token' in query_fragment:
164163
kwargs['at_hash'] = token.at_hash
165-
id_token_dic = create_id_token(**kwargs)
164+
165+
create_id_token_hook = settings.import_hook(
166+
'OIDC_IDTOKEN_CREATE_HOOK'
167+
)
168+
id_token_dic = create_id_token_hook(**kwargs)
166169

167170
# Check if response_type must include id_token in the response.
168171
if self.params['response_type'] in ['id_token', 'id_token token', 'code id_token', 'code id_token token']:

oidc_provider/lib/endpoints/token.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def create_access_token_response_dic(self):
166166
self.client,
167167
self.params['scope'].split(' '))
168168

169-
id_token_dic = create_id_token(
169+
create_id_token_hook = settings.import_hook(
170+
'OIDC_IDTOKEN_CREATE_HOOK'
171+
)
172+
173+
id_token_dic = create_id_token_hook(
170174
user=self.user,
171175
aud=self.client.client_id,
172176
nonce='self.code.nonce',
@@ -194,8 +198,12 @@ def create_code_response_dic(self):
194198
client=self.code.client,
195199
scope=self.code.scope)
196200

201+
create_id_token_hook = settings.import_hook(
202+
'OIDC_IDTOKEN_CREATE_HOOK'
203+
)
204+
197205
if self.code.is_authentication:
198-
id_token_dic = create_id_token(
206+
id_token_dic = create_id_token_hook(
199207
user=self.code.user,
200208
aud=self.client.client_id,
201209
nonce=self.code.nonce,
@@ -238,8 +246,11 @@ def create_refresh_response_dic(self):
238246
scope=scope)
239247

240248
# If the Token has an id_token it's an Authentication request.
249+
create_id_token_hook = settings.import_hook(
250+
'OIDC_IDTOKEN_CREATE_HOOK'
251+
)
241252
if self.token.id_token:
242-
id_token_dic = create_id_token(
253+
id_token_dic = create_id_token_hook(
243254
user=self.token.user,
244255
aud=self.client.client_id,
245256
nonce=None,

oidc_provider/settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def OIDC_IDTOKEN_PROCESSING_HOOK(self):
131131
"""
132132
return 'oidc_provider.lib.utils.common.default_idtoken_processing_hook'
133133

134+
@property
135+
def OIDC_IDTOKEN_CREATE_HOOK(self):
136+
"""
137+
OPTIONAL. A string with the location of your hook.
138+
Used to create a dictionary that will be the payload of the id_token.
139+
"""
140+
return 'oidc_provider.lib.utils.token.create_id_token'
141+
134142
@property
135143
def OIDC_GRANT_TYPE_PASSWORD_ENABLE(self):
136144
"""
@@ -171,6 +179,11 @@ def import_from_str(value):
171179
raise ImportError(msg)
172180

173181

182+
def import_hook(hook_name):
183+
hook_path = get(hook_name.upper())
184+
return import_from_str(hook_path)
185+
186+
174187
def get(name, import_str=False):
175188
"""
176189
Helper function to use inside the package.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='django-oidc-provider',
13-
version='0.5.4',
13+
version='0.5.5',
1414
packages=find_packages(),
1515
include_package_data=True,
1616
license='MIT License',

0 commit comments

Comments
 (0)