@@ -83,6 +83,7 @@ def __init__(
8383 services : Optional [dict ] = None ,
8484 jwks_uri : Optional [str ] = "" ,
8585 httpc_params : Optional [dict ] = None ,
86+ client_type : Optional [str ] = ""
8687 ):
8788 self .extra = {}
8889 if httpc_params :
@@ -98,7 +99,8 @@ def __init__(
9899 _kj = None
99100
100101 self ._service_context = ServiceContext (
101- keyjar = keyjar , config = config , jwks_uri = jwks_uri , httpc_params = self .httpc_params
102+ keyjar = keyjar , config = config , jwks_uri = jwks_uri , httpc_params = self .httpc_params ,
103+ client_type = client_type
102104 )
103105
104106 if config :
@@ -113,13 +115,6 @@ def __init__(
113115 metadata = config .conf .get ("metadata" , {}),
114116 usage = config .conf .get ("usage" , {}))
115117
116- # MUST not overwrite service specific usage and metadata
117- for key , val in config .conf .get ("usage" , {}).items ():
118- self .set_usage_value (key , val )
119-
120- for key , val in config .conf .get ("metadata" , {}).items ():
121- self .set_metadata_value (key , val )
122-
123118 self .setup_client_authn_methods (config )
124119
125120 jwks_uri = jwks_uri or self .get_metadata_value ("jwks_uri" )
@@ -161,7 +156,7 @@ def get_entity(self):
161156 return self
162157
163158 def get_client_id (self ):
164- return self ._service_context .get_metadata ( "client_id" )
159+ return self ._service_context .get_client_id ( )
165160
166161 def setup_client_authn_methods (self , config ):
167162 self ._service_context .client_authn_method = client_auth_setup (
@@ -172,32 +167,32 @@ def collect_metadata(self):
172167 res = {}
173168 for service in self ._service .values ():
174169 res .update (service .metadata )
175- res .update (self ._service_context .metadata )
170+ res .update (self ._service_context .specs . get_all () )
176171 return res
177172
178173 def collect_usage (self ):
179174 res = {}
180175 for service in self ._service .values ():
181176 res .update (service .usage )
182- res .update (self ._service_context .usage )
177+ res .update (self ._service_context .specs . usage )
183178 return res
184179
185180 def get_metadata_value (self , attribute , default = None ):
186181 for service in self ._service .values ():
187182 if attribute in service .metadata_attributes :
188183 return service .get_metadata (attribute , default )
189184
190- if attribute in self ._service_context .metadata_attributes :
191- return self ._service_context .get_metadata (attribute , default )
185+ if attribute in self ._service_context .specs . attributes :
186+ return self ._service_context .specs . get_metadata (attribute , default )
192187
193- raise KeyError (f"Unknown metadata attribute: { attribute } " )
188+ raise KeyError (f"Unknown specs attribute: { attribute } " )
194189
195190 def get_metadata_attributes (self ):
196191 attr = []
197192 for service in self ._service .values ():
198193 attr .extend (list (service .metadata_attributes .keys ()))
199194
200- attr .extend (list (self ._service_context .metadata_attributes .keys ()))
195+ attr .extend (list (self ._service_context .specs . attributes .keys ()))
201196
202197 return attr
203198
@@ -212,8 +207,8 @@ def value_in_metadata_attribute(self, attribute, value):
212207 if value == _val :
213208 return True
214209
215- if attribute in self ._service_context .metadata_attributes .keys ():
216- _val = self ._service_context .get_metadata (attribute )
210+ if attribute in self ._service_context .specs . attributes .keys ():
211+ _val = self ._service_context .specs . get_metadata (attribute )
217212 if isinstance (_val , list ):
218213 if value in _val :
219214 return True
@@ -229,8 +224,8 @@ def will_use(self, attribute):
229224 if service .usage .get (attribute ):
230225 return True
231226
232- if attribute in self ._service_context .usage_rules .keys ():
233- if self ._service_context .usage . get (attribute ):
227+ if attribute in self ._service_context .specs . rules .keys ():
228+ if self ._service_context .specs . get_usage (attribute ):
234229 return True
235230 return False
236231
@@ -249,18 +244,18 @@ def set_metadata_value(self, attribute, value):
249244 service .metadata [attribute ] = value
250245 return True
251246
252- if attribute in self ._service_context .metadata_attributes :
253- _def_val = self ._service_context .metadata_attributes [attribute ]
247+ if attribute in self ._service_context .specs . attributes :
248+ _def_val = self ._service_context .specs . attributes [attribute ]
254249 if _def_val is None :
255- self ._service_context .metadata [ attribute ] = value
250+ self ._service_context .specs . set_metadata ( attribute , value )
256251 return True
257252 else :
258- if self ._service_context .metadata [ attribute ] == _def_val :
259- self ._service_context .metadata [ attribute ] = value
253+ if self ._service_context .specs . get_metadata ( attribute , _def_val ) :
254+ self ._service_context .specs . set_metadata ( attribute , value )
260255 return True
261256 return True
262257
263- logger .info (f"Unknown set metadata attribute: { attribute } " )
258+ logger .info (f"Unknown set specs attribute: { attribute } " )
264259 return False
265260
266261 def set_usage_value (self , attribute , value ):
@@ -278,14 +273,14 @@ def set_usage_value(self, attribute, value):
278273 service .usage [attribute ] = value
279274 return True
280275
281- if attribute in self ._service_context .usage_rules :
282- _def_val = self ._service_context .usage_rules [attribute ]
276+ if attribute in self ._service_context .specs . rules :
277+ _def_val = self ._service_context .specs . rules [attribute ]
283278 if _def_val is None :
284- self ._service_context .usage [ attribute ] = value
279+ self ._service_context .specs . set_usage ( attribute , value )
285280 return True
286281 else :
287- if self ._service_context .usage [attribute ] == _def_val :
288- self ._service_context .usage [ attribute ] = value
282+ if self ._service_context .specs . usage [attribute ] == _def_val :
283+ self ._service_context .specs . set_usage ( attribute , value )
289284 return True
290285
291286 logger .info (f"Unknown set usage attribute: { attribute } " )
@@ -299,9 +294,10 @@ def get_usage_value(self, attribute, default=None):
299294 else :
300295 return default
301296
302- if attribute in self ._service_context .usage_rules :
303- if attribute in self ._service_context .usage :
304- return self ._service_context .usage [attribute ]
297+ if attribute in self ._service_context .specs .rules :
298+ _val = self ._service_context .specs .get_usage (attribute )
299+ if _val :
300+ return _val
305301 else :
306302 return default
307303
@@ -319,10 +315,10 @@ def construct_uris(self, issuer, hash_seed, callback):
319315 for service in self ._service .values ():
320316 service .construct_uris (_base_url , _hex )
321317
322- if not self ._service_context .get_metadata ("redirect_uris" ):
323- self ._service_context .construct_redirect_uris (_base_url , _hex , callback )
318+ if not self ._service_context .specs . get_metadata ("redirect_uris" ):
319+ self ._service_context .specs . construct_redirect_uris (_base_url , _hex , callback )
324320
325- self ._service_context .construct_uris (_base_url , _hex )
321+ self ._service_context .specs . construct_uris (_base_url , _hex )
326322
327323 def backward_compatibility (self , config ):
328324 _uris = config .get ("redirect_uris" )
@@ -357,14 +353,14 @@ def config_args(self):
357353 "usage" : service .usage_rules
358354 }
359355 res ["" ] = {
360- "metadata" : self ._service_context .metadata_attributes ,
361- "usage" : self ._service_context .usage_rules
356+ "metadata" : self ._service_context .specs . attributes ,
357+ "usage" : self ._service_context .specs . rules
362358 }
363359 return res
364360
365361 def get_callback_uris (self ):
366362 res = []
367363 for service in self ._service .values ():
368364 res .extend (service .callback_uris )
369- res .extend (self ._service_context .callback_uris )
365+ res .extend (self ._service_context .specs . callback_uris )
370366 return res
0 commit comments