MCPcopy
hub / github.com/authlib/authlib / KeySet

Class KeySet

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

This class represents a JSON Web Key Set.

Source from the content-addressed store, hash-verified

2
3
4class KeySet:
5 """This class represents a JSON Web Key Set."""
6
7 def __init__(self, keys):
8 self.keys = keys
9
10 def as_dict(self, is_private=False, **params):
11 """Represent this key as a dict of the JSON Web Key Set."""
12 return {"keys": [k.as_dict(is_private, **params) for k in self.keys]}
13
14 def as_json(self, is_private=False, **params):
15 """Represent this key set as a JSON string."""
16 obj = self.as_dict(is_private, **params)
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 5

test_jwk_key_setFunction · 0.90
import_key_setMethod · 0.85

Calls

no outgoing calls

Tested by 4

test_jwk_key_setFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…