MCPcopy
hub / github.com/authlib/authlib / import_any_key

Function import_any_key

authlib/_joserfc_helpers.py:11–48  ·  view source on GitHub ↗
(data: Any)

Source from the content-addressed store, hash-verified

9
10
11def import_any_key(data: Any):
12 if "authlib.jose" in sys.modules:
13 from authlib.jose.rfc7518 import ECKey
14 from authlib.jose.rfc7518 import OctKey
15 from authlib.jose.rfc7518 import RSAKey
16 from authlib.jose.rfc8037 import OKPKey
17
18 if isinstance(data, (OctKey, RSAKey, ECKey, OKPKey)):
19 deprecate("Please use joserfc to import keys.", version="2.0.0")
20 return import_key(data.as_dict(is_private=not data.public_only))
21
22 if (
23 isinstance(data, str)
24 and data.strip().startswith("{")
25 and data.strip().endswith("}")
26 ):
27 deprecate(
28 "Please use OctKey, RSAKey, ECKey, OKPKey, and KeySet directly.",
29 version="2.0.0",
30 )
31 data = json_loads(data)
32
33 if isinstance(data, (str, bytes)):
34 deprecate(
35 "Please use OctKey, RSAKey, ECKey, OKPKey, and KeySet directly.",
36 version="2.0.0",
37 )
38 return import_key(data)
39
40 elif isinstance(data, dict):
41 if "keys" in data:
42 deprecate(
43 "Please `KeySet.import_key_set` from `joserfc.jwk` to import jwks.",
44 version="2.0.0",
45 )
46 return KeySet.import_key_set(data)
47 return import_key(data)
48 return data

Callers 15

authenticate_tokenMethod · 0.90
__call__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__call__Method · 0.90
encode_id_tokenMethod · 0.90

Calls 4

deprecateFunction · 0.90
json_loadsFunction · 0.90
import_key_setMethod · 0.80
as_dictMethod · 0.45

Tested by 4

test_import_raw_strFunction · 0.72
test_import_key_setFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…