Skip to content

Commit d95783a

Browse files
author
Chris Pickett
committed
ARCH-435 | Add hook for encode_id_token
1 parent 21f74c7 commit d95783a

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
### [Unreleased]
66

7+
### [0.6.0-orm] - 2018-10-03
8+
9+
##### Changed
10+
- Added `OIDC_IDTOKEN_ENCODE_HOOK` setting to allow for setting function that's used when encoding an id_token.
711

812
### [0.5.5] - 2018-09-11
913

oidc_provider/lib/endpoints/authorize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from oidc_provider.lib.utils.token import (
2323
create_code,
2424
create_token,
25-
encode_id_token,
2625
)
2726
from oidc_provider.models import (
2827
Client,
@@ -167,6 +166,10 @@ def create_response_uri(self):
167166
)
168167
id_token_dic = create_id_token_hook(**kwargs)
169168

169+
encode_id_token = settings.import_hook(
170+
'OIDC_IDTOKEN_ENCODE_HOOK'
171+
)
172+
170173
# Check if response_type must include id_token in the response.
171174
if self.params['response_type'] in ['id_token', 'id_token token', 'code id_token', 'code id_token token']:
172175
query_fragment['id_token'] = encode_id_token(id_token_dic, self.client)

oidc_provider/lib/endpoints/token.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from oidc_provider.lib.utils.token import (
1919
create_id_token,
2020
create_token,
21-
encode_id_token,
2221
)
2322
from oidc_provider.models import (
2423
Client,
@@ -37,6 +36,9 @@ def __init__(self, request):
3736
self.user = None
3837
self._extract_params()
3938

39+
def _encode_id_token(self, *args):
40+
return settings.import_hook('OIDC_IDTOKEN_ENCODE_HOOK')(*args)
41+
4042
def _extract_params(self):
4143
client_id, client_secret = self._extract_client_auth()
4244

@@ -187,7 +189,7 @@ def create_access_token_response_dic(self):
187189
'refresh_token': token.refresh_token,
188190
'expires_in': settings.get('OIDC_TOKEN_EXPIRE'),
189191
'token_type': 'bearer',
190-
'id_token': encode_id_token(id_token_dic, token.client),
192+
'id_token': self._encode_id_token(id_token_dic, token.client),
191193
}
192194

193195
def create_code_response_dic(self):
@@ -226,7 +228,7 @@ def create_code_response_dic(self):
226228
'refresh_token': token.refresh_token,
227229
'token_type': 'bearer',
228230
'expires_in': settings.get('OIDC_TOKEN_EXPIRE'),
229-
'id_token': encode_id_token(id_token_dic, token.client),
231+
'id_token': self._encode_id_token(id_token_dic, token.client),
230232
}
231233

232234
return dic
@@ -273,7 +275,7 @@ def create_refresh_response_dic(self):
273275
'refresh_token': token.refresh_token,
274276
'token_type': 'bearer',
275277
'expires_in': settings.get('OIDC_TOKEN_EXPIRE'),
276-
'id_token': encode_id_token(id_token_dic, self.token.client),
278+
'id_token': self._encode_id_token(id_token_dic, self.token.client),
277279
}
278280

279281
return dic

oidc_provider/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ def OIDC_IDTOKEN_CREATE_HOOK(self):
139139
"""
140140
return 'oidc_provider.lib.utils.token.create_id_token'
141141

142+
@property
143+
def OIDC_IDTOKEN_ENCODE_HOOK(self):
144+
"""
145+
OPTIONAL. A string with the location of your hook.
146+
Used to encode a dictionary that will be the payload of the id_token.
147+
"""
148+
return 'oidc_provider.lib.utils.token.encode_id_token'
149+
142150
@property
143151
def OIDC_GRANT_TYPE_PASSWORD_ENABLE(self):
144152
"""

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.5',
13+
version='0.6.0-orm',
1414
packages=find_packages(),
1515
include_package_data=True,
1616
license='MIT License',

0 commit comments

Comments
 (0)