44from typing import List
55from typing import Optional
66
7- from abstorage .base import LabeledAbstractStorage
87from requests import request
98
109from .jwe .jwe import alg2keytype as jwe_alg2keytype
@@ -40,7 +39,7 @@ class KeyJar(object):
4039
4140 def __init__ (self , ca_certs = None , verify_ssl = True , keybundle_cls = KeyBundle ,
4241 remove_after = 3600 , httpc = None , httpc_params = None , storage_conf = None ,
43- abstract_storage_cls = LabeledAbstractStorage ):
42+ abstract_storage_cls = None ):
4443 """
4544 KeyJar init function
4645
@@ -56,6 +55,8 @@ def __init__(self, ca_certs=None, verify_ssl=True, keybundle_cls=KeyBundle,
5655 if storage_conf is None :
5756 self ._issuers = {}
5857 else :
58+ if not abstract_storage_cls :
59+ raise ValueError ('Missing storage class specification' )
5960 self ._issuers = abstract_storage_cls (storage_conf )
6061
6162 self .storage_conf = storage_conf
@@ -407,7 +408,7 @@ def export_jwks(self, private=False, issuer_id="", usage=None):
407408 """
408409 _issuer = self ._get_issuer (issuer_id = issuer_id )
409410 if _issuer is None :
410- return {}
411+ return {"keys" : [] }
411412
412413 keys = []
413414 for kb in _issuer :
@@ -437,11 +438,12 @@ def import_jwks(self, jwks, issuer_id):
437438 _keys = jwks ["keys" ]
438439 except KeyError :
439440 raise ValueError ('Not a proper JWKS' )
440- else :
441+
442+ if _keys :
441443 _issuer = self .return_issuer (issuer_id = issuer_id )
442444 _issuer .add (self .keybundle_cls (_keys , httpc = self .httpc ,
443445 httpc_params = self .httpc_params ))
444- self [issuer_id ] = _issuer
446+ self [issuer_id ] = _issuer
445447
446448 def import_jwks_as_json (self , jwks , issuer_id ):
447449 """
@@ -776,7 +778,7 @@ def build_keyjar(key_conf, kid_template="", keyjar=None, issuer_id='', storage_c
776778
777779
778780def init_key_jar (public_path = '' , private_path = '' , key_defs = '' , issuer_id = '' , read_only = True ,
779- storage_conf = None ):
781+ storage_conf = None , abstract_storage_cls = None ):
780782 """
781783 A number of cases here:
782784
@@ -888,7 +890,10 @@ def init_key_jar(public_path='', private_path='', key_defs='', issuer_id='', rea
888890 else :
889891 _issuer = build_keyissuer (key_defs , issuer_id = issuer_id )
890892
891- keyjar = KeyJar (storage_conf = storage_conf )
893+ if _issuer is None :
894+ raise ValueError ('Could not find any keys' )
895+
896+ keyjar = KeyJar (storage_conf = storage_conf , abstract_storage_cls = abstract_storage_cls )
892897 keyjar [issuer_id ] = _issuer
893898 return keyjar
894899
0 commit comments