usso-jwt 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {usso_jwt-0.2.2/src/usso_jwt.egg-info → usso_jwt-0.2.4}/PKG-INFO +1 -1
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/pyproject.toml +1 -1
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/base.py +2 -2
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/ecdsa.py +19 -9
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/eddsa.py +16 -3
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/hmac.py +1 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/rsa.py +32 -16
- {usso_jwt-0.2.2 → usso_jwt-0.2.4/src/usso_jwt.egg-info}/PKG-INFO +1 -1
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/LICENSE.txt +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/MANIFEST.in +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/README.md +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/pytest.ini +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/setup.cfg +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/__init__.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/algorithms/__init__.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/config.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/enums.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/exceptions.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/schemas.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/sign.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/utils.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt/verify.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt.egg-info/SOURCES.txt +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt.egg-info/dependency_links.txt +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt.egg-info/requires.txt +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/src/usso_jwt.egg-info/top_level.txt +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/tests/test_jwt.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/tests/test_sign.py +0 -0
- {usso_jwt-0.2.2 → usso_jwt-0.2.4}/tests/test_verify.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: usso-jwt
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A simple and lightweight Python package for handling JWT (JSON Web Token) operations with USSO (Unified Single Sign-On).
|
|
5
5
|
Author-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
6
6
|
Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "usso-jwt"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.4"
|
|
8
8
|
description = "A simple and lightweight Python package for handling JWT (JSON Web Token) operations with USSO (Unified Single Sign-On)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -66,9 +66,9 @@ class KeyAlgorithm(ABC):
|
|
|
66
66
|
def SUPPORTED_ALGORITHMS(self) -> set[str]:
|
|
67
67
|
"""Set of supported algorithms for this implementation."""
|
|
68
68
|
|
|
69
|
-
@
|
|
69
|
+
@classmethod
|
|
70
70
|
@abstractmethod
|
|
71
|
-
def load_key(key: dict | bytes, password: bytes | None = None):
|
|
71
|
+
def load_key(cls, key: dict | bytes, password: bytes | None = None):
|
|
72
72
|
"""Load key from JWK dict or raw bytes."""
|
|
73
73
|
|
|
74
74
|
@classmethod
|
|
@@ -39,20 +39,29 @@ class ECDSAAlgorithm(KeyAlgorithm):
|
|
|
39
39
|
if isinstance(key, ec.EllipticCurvePrivateKey):
|
|
40
40
|
return key
|
|
41
41
|
if isinstance(key, dict):
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return ec.EllipticCurvePrivateNumbers(
|
|
49
|
-
d, ec.EllipticCurvePublicNumbers(x, y, curve)
|
|
50
|
-
).private_key(default_backend())
|
|
42
|
+
return cls.load_jwk(key)
|
|
43
|
+
# Load from PEM
|
|
44
|
+
if isinstance(key, bytes) and key.startswith(b"-----BEGIN"):
|
|
45
|
+
return serialization.load_pem_private_key(
|
|
46
|
+
key, password=password, backend=default_backend()
|
|
47
|
+
)
|
|
51
48
|
# Load from DER
|
|
52
49
|
return serialization.load_der_private_key(
|
|
53
50
|
key, password=password, backend=default_backend()
|
|
54
51
|
)
|
|
55
52
|
|
|
53
|
+
@classmethod
|
|
54
|
+
def load_jwk(cls, key: dict) -> ec.EllipticCurvePrivateKey:
|
|
55
|
+
"""Load a key from JWK dict."""
|
|
56
|
+
return ec.EllipticCurvePrivateNumbers(
|
|
57
|
+
int.from_bytes(b64url_decode(key["d"]), "big"),
|
|
58
|
+
ec.EllipticCurvePublicNumbers(
|
|
59
|
+
int.from_bytes(b64url_decode(key["x"]), "big"),
|
|
60
|
+
int.from_bytes(b64url_decode(key["y"]), "big"),
|
|
61
|
+
cls.SUPPORTED_ALGORITHMS[key.get("alg", "ES256")](),
|
|
62
|
+
),
|
|
63
|
+
).private_key(default_backend())
|
|
64
|
+
|
|
56
65
|
@classmethod
|
|
57
66
|
def sign(
|
|
58
67
|
cls,
|
|
@@ -236,6 +245,7 @@ class ECDSAKey(AbstractKey):
|
|
|
236
245
|
public_key.curve.key_size // 8, "big"
|
|
237
246
|
)
|
|
238
247
|
),
|
|
248
|
+
"use": "sig",
|
|
239
249
|
"kid": kid or self.kid,
|
|
240
250
|
}
|
|
241
251
|
|
|
@@ -11,8 +11,9 @@ class EdDSAAlgorithm(KeyAlgorithm):
|
|
|
11
11
|
|
|
12
12
|
SUPPORTED_ALGORITHMS = {"EdDSA", "EDDSA", "Ed25519", "ED25519"}
|
|
13
13
|
|
|
14
|
-
@
|
|
14
|
+
@classmethod
|
|
15
15
|
def load_key(
|
|
16
|
+
cls,
|
|
16
17
|
key: dict | bytes | ed25519.Ed25519PrivateKey,
|
|
17
18
|
password: bytes | None = None,
|
|
18
19
|
) -> ed25519.Ed25519PrivateKey:
|
|
@@ -28,14 +29,26 @@ class EdDSAAlgorithm(KeyAlgorithm):
|
|
|
28
29
|
"""
|
|
29
30
|
if isinstance(key, ed25519.Ed25519PrivateKey):
|
|
30
31
|
return key
|
|
32
|
+
# Load from JWK
|
|
31
33
|
if isinstance(key, dict):
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
+
return cls.load_jwk(key)
|
|
35
|
+
# Load from PEM
|
|
36
|
+
if isinstance(key, bytes) and key.startswith(b"-----BEGIN"):
|
|
37
|
+
return serialization.load_pem_private_key(
|
|
38
|
+
key, password=password, backend=default_backend()
|
|
34
39
|
)
|
|
40
|
+
# Load from DER
|
|
35
41
|
return serialization.load_der_private_key(
|
|
36
42
|
key, password=password, backend=default_backend()
|
|
37
43
|
)
|
|
38
44
|
|
|
45
|
+
@classmethod
|
|
46
|
+
def load_jwk(cls, key: dict) -> ed25519.Ed25519PrivateKey:
|
|
47
|
+
"""Load a key from JWK dict."""
|
|
48
|
+
return ed25519.Ed25519PrivateKey.from_private_bytes(
|
|
49
|
+
b64url_decode(key["d"])
|
|
50
|
+
)
|
|
51
|
+
|
|
39
52
|
@classmethod
|
|
40
53
|
def sign(
|
|
41
54
|
cls,
|
|
@@ -19,9 +19,11 @@ class RSAAlgorithm(KeyAlgorithm):
|
|
|
19
19
|
"PS512": hashes.SHA512,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
@
|
|
22
|
+
@classmethod
|
|
23
23
|
def load_key(
|
|
24
|
-
|
|
24
|
+
cls,
|
|
25
|
+
key: dict | bytes | rsa.RSAPrivateKey,
|
|
26
|
+
password: bytes | None = None,
|
|
25
27
|
) -> rsa.RSAPrivateKey:
|
|
26
28
|
"""
|
|
27
29
|
Load RSA private key from JWK dict or PEM bytes.
|
|
@@ -36,25 +38,34 @@ class RSAAlgorithm(KeyAlgorithm):
|
|
|
36
38
|
if isinstance(key, rsa.RSAPrivateKey):
|
|
37
39
|
return key
|
|
38
40
|
if isinstance(key, dict):
|
|
39
|
-
|
|
40
|
-
n = int.from_bytes(b64url_decode(key["n"]), "big")
|
|
41
|
-
e = int.from_bytes(b64url_decode(key["e"]), "big")
|
|
42
|
-
d = int.from_bytes(b64url_decode(key["d"]), "big")
|
|
43
|
-
return rsa.RSAPrivateNumbers(
|
|
44
|
-
p=int.from_bytes(b64url_decode(key["p"]), "big"),
|
|
45
|
-
q=int.from_bytes(b64url_decode(key["q"]), "big"),
|
|
46
|
-
d=d,
|
|
47
|
-
dmp1=int.from_bytes(b64url_decode(key["dp"]), "big"),
|
|
48
|
-
dmq1=int.from_bytes(b64url_decode(key["dq"]), "big"),
|
|
49
|
-
iqmp=int.from_bytes(b64url_decode(key["qi"]), "big"),
|
|
50
|
-
public_numbers=rsa.RSAPublicNumbers(e, n),
|
|
51
|
-
).private_key(default_backend())
|
|
41
|
+
return cls.load_jwk(key)
|
|
52
42
|
|
|
43
|
+
# Load from PEM
|
|
44
|
+
if isinstance(key, bytes) and key.startswith(b"-----BEGIN"):
|
|
45
|
+
return serialization.load_pem_private_key(
|
|
46
|
+
key, password=password, backend=default_backend()
|
|
47
|
+
)
|
|
53
48
|
# Load from DER
|
|
54
49
|
return serialization.load_der_private_key(
|
|
55
50
|
key, password=password, backend=default_backend()
|
|
56
51
|
)
|
|
57
52
|
|
|
53
|
+
@classmethod
|
|
54
|
+
def load_jwk(cls, key: dict) -> rsa.RSAPrivateKey:
|
|
55
|
+
"""Load a key from JWK dict."""
|
|
56
|
+
return rsa.RSAPrivateNumbers(
|
|
57
|
+
p=int.from_bytes(b64url_decode(key["p"]), "big"),
|
|
58
|
+
q=int.from_bytes(b64url_decode(key["q"]), "big"),
|
|
59
|
+
d=int.from_bytes(b64url_decode(key["d"]), "big"),
|
|
60
|
+
dmp1=int.from_bytes(b64url_decode(key["dp"]), "big"),
|
|
61
|
+
dmq1=int.from_bytes(b64url_decode(key["dq"]), "big"),
|
|
62
|
+
iqmp=int.from_bytes(b64url_decode(key["qi"]), "big"),
|
|
63
|
+
public_numbers=rsa.RSAPublicNumbers(
|
|
64
|
+
int.from_bytes(b64url_decode(key["e"]), "big"),
|
|
65
|
+
int.from_bytes(b64url_decode(key["n"]), "big"),
|
|
66
|
+
),
|
|
67
|
+
).private_key(default_backend())
|
|
68
|
+
|
|
58
69
|
@classmethod
|
|
59
70
|
def sign(
|
|
60
71
|
cls,
|
|
@@ -242,11 +253,16 @@ class RSAKey(AbstractKey):
|
|
|
242
253
|
)
|
|
243
254
|
),
|
|
244
255
|
"e": b64url_encode(
|
|
256
|
+
# public_key.public_numbers().e.to_bytes(
|
|
257
|
+
# public_key.key_size // 8,
|
|
258
|
+
# "big",
|
|
259
|
+
# )
|
|
245
260
|
public_key.public_numbers().e.to_bytes(
|
|
246
|
-
public_key.
|
|
261
|
+
(public_key.public_numbers().e.bit_length() + 7) // 8,
|
|
247
262
|
"big",
|
|
248
263
|
)
|
|
249
264
|
),
|
|
265
|
+
"use": "sig",
|
|
250
266
|
"kid": kid or self.kid,
|
|
251
267
|
}
|
|
252
268
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: usso-jwt
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A simple and lightweight Python package for handling JWT (JSON Web Token) operations with USSO (Unified Single Sign-On).
|
|
5
5
|
Author-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
6
6
|
Maintainer-email: Mahdi Kiani <mahdikiany@gmail.com>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|