|
3 | 3 | from cryptojwt.jws.utils import left_hash |
4 | 4 | from cryptojwt.jwt import JWT |
5 | 5 |
|
| 6 | +from oidcendpoint.endpoint import construct_provider_info |
6 | 7 | from oidcendpoint.userinfo import collect_user_info |
7 | 8 | from oidcendpoint.userinfo import userinfo_in_id_token_claims |
8 | 9 |
|
|
18 | 19 | DEF_LIFETIME = 300 |
19 | 20 |
|
20 | 21 |
|
| 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 | + |
21 | 53 | def get_sign_and_encrypt_algorithms( |
22 | 54 | endpoint_context, client_info, payload_type, sign=False, encrypt=False |
23 | 55 | ): |
@@ -72,10 +104,17 @@ def get_sign_and_encrypt_algorithms( |
72 | 104 |
|
73 | 105 |
|
74 | 106 | 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 | + |
75 | 113 | def __init__(self, endpoint_context, **kwargs): |
76 | 114 | self.endpoint_context = endpoint_context |
77 | 115 | self.kwargs = kwargs |
78 | 116 | self.scope_to_claims = None |
| 117 | + self.provider_info = construct_provider_info(self.default_capabilities, **kwargs) |
79 | 118 |
|
80 | 119 | def payload( |
81 | 120 | self, |
@@ -229,19 +268,14 @@ def make(self, req, sess_info, authn_req=None, user_claims=False, **kwargs): |
229 | 268 | else: |
230 | 269 | userinfo.update(info) |
231 | 270 |
|
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") |
239 | 275 |
|
240 | 276 | if req_sid: |
241 | 277 | 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) |
245 | 279 | } |
246 | 280 | else: |
247 | 281 | xargs = {} |
|
0 commit comments