Skip to content
This repository was archived by the owner on Jun 12, 2021. It is now read-only.

Commit 9d8c9d4

Browse files
committed
Whether or sid is included in the ID Token is dependent on logout support.
1 parent 006b11d commit 9d8c9d4

1 file changed

Lines changed: 44 additions & 10 deletions

File tree

src/oidcendpoint/id_token.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from cryptojwt.jws.utils import left_hash
44
from cryptojwt.jwt import JWT
55

6+
from oidcendpoint.endpoint import construct_provider_info
67
from oidcendpoint.userinfo import collect_user_info
78
from oidcendpoint.userinfo import userinfo_in_id_token_claims
89

@@ -18,6 +19,37 @@
1819
DEF_LIFETIME = 300
1920

2021

22+
def include_session_id(endpoint_context, client_id, where):
23+
"""
24+
25+
:param endpoint_context:
26+
:param client_id:
27+
:param dir: front or back
28+
:return:
29+
"""
30+
_pinfo = endpoint_context.provider_info
31+
32+
# Am the OP supposed to support {dir}-channel log out and if so can
33+
# it pass sid in logout token and ID Token
34+
for param in ["{}channel_logout_supported",
35+
"{}channel_logout_session_supported"]:
36+
try:
37+
_supported = _pinfo[param.format(where)]
38+
except KeyError:
39+
return False
40+
else:
41+
if not _supported:
42+
return False
43+
44+
# Does the client support back-channel logout ?
45+
try:
46+
_val = endpoint_context.cdb[client_id]["{}channel_logout_uri".format(where)]
47+
except KeyError:
48+
return False
49+
50+
return True
51+
52+
2153
def get_sign_and_encrypt_algorithms(
2254
endpoint_context, client_info, payload_type, sign=False, encrypt=False
2355
):
@@ -72,10 +104,17 @@ def get_sign_and_encrypt_algorithms(
72104

73105

74106
class IDToken(object):
107+
default_capabilities = {
108+
"id_token_signing_alg_values_supported": None,
109+
"id_token_encryption_alg_values_supported": None,
110+
"id_token_encryption_enc_values_supported": None
111+
}
112+
75113
def __init__(self, endpoint_context, **kwargs):
76114
self.endpoint_context = endpoint_context
77115
self.kwargs = kwargs
78116
self.scope_to_claims = None
117+
self.provider_info = construct_provider_info(self.default_capabilities, **kwargs)
79118

80119
def payload(
81120
self,
@@ -229,19 +268,14 @@ def make(self, req, sess_info, authn_req=None, user_claims=False, **kwargs):
229268
else:
230269
userinfo.update(info)
231270

232-
try:
233-
req_sid = _cinfo["frontchannel_logout_session_required"]
234-
except KeyError:
235-
try:
236-
req_sid = _cinfo["backchannel_logout_session_required"]
237-
except KeyError:
238-
req_sid = False
271+
# Should I add session ID
272+
req_sid = include_session_id(_context, _client_id, "back") or include_session_id(_context,
273+
_client_id,
274+
"front")
239275

240276
if req_sid:
241277
xargs = {
242-
"sid": _context.sdb.get_sid_by_sub_and_client_id(
243-
sess_info["sub"], _client_id
244-
)
278+
"sid": _context.sdb.get_sid_by_sub_and_client_id(sess_info["sub"], _client_id)
245279
}
246280
else:
247281
xargs = {}

0 commit comments

Comments
 (0)