Find the key matches the given kid value. :param kid: A string of kid :return: Key instance :raise: ValueError
(self, kid, **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 | |
| 40 | def _filter_keys_by_params(keys, **params): |