Skip to content

Commit 63e1162

Browse files
committed
Refactored key jar making.
Dealt with getting a jwks_uri in a static provider info configuration. Response_types as list or space separated string should both work.
1 parent 4ac1af6 commit 63e1162

File tree

5 files changed

+88
-63
lines changed

5 files changed

+88
-63
lines changed

src/idpyoidc/client/oauth2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def __init__(
8282
else:
8383
httpc_params = {"verify": False}
8484

85+
jwks_uri = jwks_uri or config.get('jwks_uri', '')
86+
8587
Entity.__init__(
8688
self,
8789
keyjar=keyjar,

src/idpyoidc/client/oauth2/stand_alone_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ def get_access_and_id_token(
463463
state = authorization_response["state"]
464464

465465
_req_attr = _context.cstate.get_set(state, AuthorizationRequest)
466-
_resp_type = set(_req_attr["response_type"].split(" "))
466+
if isinstance(_req_attr["response_type"], list):
467+
_resp_type = set(_req_attr["response_type"])
468+
else:
469+
_resp_type = set(_req_attr["response_type"].split(" "))
467470

468471
access_token = None
469472
id_token = None

src/idpyoidc/client/service_context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def __init__(
171171

172172
self.keyjar = self.claims.load_conf(config.conf, supports=self.supports(), keyjar=keyjar)
173173

174+
_jwks_uri = self.provider_info.get('jwks_uri')
175+
if _jwks_uri:
176+
self.keyjar.load_keys(self.provider_info.get('issuer'), jwks_uri=_jwks_uri)
177+
174178
_response_types = self.get_preference(
175179
"response_types_supported", self.supports().get("response_types_supported", [])
176180
)

src/idpyoidc/message/oidc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def check_char_set(string, allowed):
240240
"encenc",
241241
"sigalg",
242242
"issuer",
243+
"iss",
243244
"allow_missing_kid",
244245
"no_kid_issuer",
245246
"trusting",

src/idpyoidc/node.py

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414

1515
def create_keyjar(
16-
keyjar: Optional[KeyJar] = None,
17-
conf: Optional[Union[dict, Configuration]] = None,
18-
key_conf: Optional[dict] = None,
19-
id: Optional[str] = "",
16+
keyjar: Optional[KeyJar] = None,
17+
conf: Optional[Union[dict, Configuration]] = None,
18+
key_conf: Optional[dict] = None,
19+
id: Optional[str] = "",
2020
):
2121
if keyjar is None:
2222
if key_conf:
@@ -45,6 +45,49 @@ def create_keyjar(
4545
return keyjar
4646

4747

48+
def make_keyjar(
49+
keyjar: Optional[Union[KeyJar, bool]] = None,
50+
config: Optional[Union[Configuration, dict]] = None,
51+
key_conf: Optional[dict] = None,
52+
issuer_id: Optional[str] = "",
53+
client_id: Optional[str] = "",
54+
):
55+
if keyjar is False:
56+
return None
57+
58+
keyjar = keyjar or config.get("keyjar")
59+
key_conf = key_conf or config.get("key_conf", config.get("keys"))
60+
61+
if not keyjar and not key_conf:
62+
keyjar = KeyJar()
63+
_jwks = config.get("jwks")
64+
if _jwks:
65+
keyjar.import_jwks_as_json(_jwks, client_id)
66+
67+
if keyjar or key_conf:
68+
# Should be either one
69+
id = issuer_id or client_id
70+
keyjar = create_keyjar(keyjar, conf=config, key_conf=key_conf, id=id)
71+
if client_id:
72+
_key = config.get("client_secret")
73+
if _key:
74+
keyjar.add_symmetric(client_id, _key)
75+
keyjar.add_symmetric("", _key)
76+
else:
77+
if client_id:
78+
_key = config.get("client_secret")
79+
if _key:
80+
keyjar = KeyJar()
81+
keyjar.add_symmetric(client_id, _key)
82+
keyjar.add_symmetric("", _key)
83+
else:
84+
keyjar = build_keyjar(DEFAULT_KEY_DEFS)
85+
if issuer_id:
86+
keyjar.import_jwks(keyjar.export_jwks(private=True), issuer_id)
87+
88+
return keyjar
89+
90+
4891
class Node:
4992
def __init__(self, upstream_get: Callable = None):
5093
self.upstream_get = upstream_get
@@ -82,15 +125,15 @@ class Unit(ImpExp):
82125
init_args = ["upstream_get"]
83126

84127
def __init__(
85-
self,
86-
upstream_get: Callable = None,
87-
keyjar: Optional[KeyJar] = None,
88-
httpc: Optional[object] = None,
89-
httpc_params: Optional[dict] = None,
90-
config: Optional[Union[Configuration, dict]] = None,
91-
key_conf: Optional[dict] = None,
92-
issuer_id: Optional[str] = "",
93-
client_id: Optional[str] = "",
128+
self,
129+
upstream_get: Callable = None,
130+
keyjar: Optional[Union[KeyJar, bool]] = None,
131+
httpc: Optional[object] = None,
132+
httpc_params: Optional[dict] = None,
133+
config: Optional[Union[Configuration, dict]] = None,
134+
key_conf: Optional[dict] = None,
135+
issuer_id: Optional[str] = "",
136+
client_id: Optional[str] = "",
94137
):
95138
ImpExp.__init__(self)
96139
self.upstream_get = upstream_get
@@ -99,35 +142,7 @@ def __init__(
99142
if config is None:
100143
config = {}
101144

102-
keyjar = keyjar or config.get("keyjar")
103-
key_conf = key_conf or config.get("key_conf", config.get("keys"))
104-
105-
if not keyjar and not key_conf:
106-
keyjar = KeyJar()
107-
_jwks = config.get("jwks")
108-
if _jwks:
109-
keyjar.import_jwks_as_json(_jwks, client_id)
110-
111-
if keyjar or key_conf:
112-
# Should be either one
113-
id = issuer_id or client_id
114-
self.keyjar = create_keyjar(keyjar, conf=config, key_conf=key_conf, id=id)
115-
if client_id:
116-
_key = config.get("client_secret")
117-
if _key:
118-
self.keyjar.add_symmetric(client_id, _key)
119-
self.keyjar.add_symmetric("", _key)
120-
else:
121-
if client_id:
122-
_key = config.get("client_secret")
123-
if _key:
124-
self.keyjar = KeyJar()
125-
self.keyjar.add_symmetric(client_id, _key)
126-
self.keyjar.add_symmetric("", _key)
127-
else:
128-
self.keyjar = build_keyjar(DEFAULT_KEY_DEFS)
129-
if issuer_id:
130-
self.keyjar.import_jwks(self.keyjar.export_jwks(private=True), issuer_id)
145+
self.keyjar = make_keyjar(keyjar, config, key_conf, issuer_id, client_id)
131146

132147
self.httpc_params = httpc_params or config.get("httpc_params", {})
133148

@@ -176,16 +191,16 @@ class ClientUnit(Unit):
176191
name = ""
177192

178193
def __init__(
179-
self,
180-
upstream_get: Callable = None,
181-
httpc: Optional[object] = None,
182-
httpc_params: Optional[dict] = None,
183-
keyjar: Optional[KeyJar] = None,
184-
context: Optional[ImpExp] = None,
185-
config: Optional[Union[Configuration, dict]] = None,
186-
# jwks_uri: Optional[str] = "",
187-
entity_id: Optional[str] = "",
188-
key_conf: Optional[dict] = None,
194+
self,
195+
upstream_get: Callable = None,
196+
httpc: Optional[object] = None,
197+
httpc_params: Optional[dict] = None,
198+
keyjar: Optional[KeyJar] = None,
199+
context: Optional[ImpExp] = None,
200+
config: Optional[Union[Configuration, dict]] = None,
201+
# jwks_uri: Optional[str] = "",
202+
entity_id: Optional[str] = "",
203+
key_conf: Optional[dict] = None,
189204
):
190205
if config is None:
191206
config = {}
@@ -217,16 +232,16 @@ def get_context_attribute(self, attr, *args):
217232
# Neither client nor Server
218233
class Collection(Unit):
219234
def __init__(
220-
self,
221-
upstream_get: Callable = None,
222-
keyjar: Optional[KeyJar] = None,
223-
httpc: Optional[object] = None,
224-
httpc_params: Optional[dict] = None,
225-
config: Optional[Union[Configuration, dict]] = None,
226-
entity_id: Optional[str] = "",
227-
key_conf: Optional[dict] = None,
228-
functions: Optional[dict] = None,
229-
claims: Optional[dict] = None,
235+
self,
236+
upstream_get: Callable = None,
237+
keyjar: Optional[KeyJar] = None,
238+
httpc: Optional[object] = None,
239+
httpc_params: Optional[dict] = None,
240+
config: Optional[Union[Configuration, dict]] = None,
241+
entity_id: Optional[str] = "",
242+
key_conf: Optional[dict] = None,
243+
functions: Optional[dict] = None,
244+
claims: Optional[dict] = None,
230245
):
231246
if config is None:
232247
config = {}

0 commit comments

Comments
 (0)