13
13
14
14
15
15
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 ] = "" ,
20
20
):
21
21
if keyjar is None :
22
22
if key_conf :
@@ -45,6 +45,49 @@ def create_keyjar(
45
45
return keyjar
46
46
47
47
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
+
48
91
class Node :
49
92
def __init__ (self , upstream_get : Callable = None ):
50
93
self .upstream_get = upstream_get
@@ -82,15 +125,15 @@ class Unit(ImpExp):
82
125
init_args = ["upstream_get" ]
83
126
84
127
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 ] = "" ,
94
137
):
95
138
ImpExp .__init__ (self )
96
139
self .upstream_get = upstream_get
@@ -99,35 +142,7 @@ def __init__(
99
142
if config is None :
100
143
config = {}
101
144
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 )
131
146
132
147
self .httpc_params = httpc_params or config .get ("httpc_params" , {})
133
148
@@ -176,16 +191,16 @@ class ClientUnit(Unit):
176
191
name = ""
177
192
178
193
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 ,
189
204
):
190
205
if config is None :
191
206
config = {}
@@ -217,16 +232,16 @@ def get_context_attribute(self, attr, *args):
217
232
# Neither client nor Server
218
233
class Collection (Unit ):
219
234
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 ,
230
245
):
231
246
if config is None :
232
247
config = {}
0 commit comments