MCPcopy
hub / github.com/authlib/authlib / find_by_kid

Method find_by_kid

authlib/jose/rfc7517/key_set.py:19–37  ·  view source on GitHub ↗

Find the key matches the given kid value. :param kid: A string of kid :return: Key instance :raise: ValueError

(self, kid, **params)

Source from the content-addressed store, hash-verified

17 return json_dumps(obj)
18
19 def find_by_kid(self, kid, **params):
20 """Find the key matches the given kid value.
21
22 :param kid: A string of kid
23 :return: Key instance
24 :raise: ValueError
25 """
26 # Proposed fix, feel free to do something else but the idea is that we take the only key
27 # of the set if no kid is specified
28 if kid is None and len(self.keys) == 1:
29 return self.keys[0]
30
31 keys = [key for key in self.keys if key.kid == kid]
32 if params:
33 keys = list(_filter_keys_by_params(keys, **params))
34
35 if keys:
36 return keys[0]
37 raise ValueError("Key not found")
38
39
40def _filter_keys_by_params(keys, **params):

Callers 6

loadsFunction · 0.80
find_encode_keyFunction · 0.80
load_keyFunction · 0.80
test_jwk_import_key_setFunction · 0.80

Calls 1

_filter_keys_by_paramsFunction · 0.85

Tested by 3

test_jwk_import_key_setFunction · 0.64