diff options
author | José Padilla <jpadilla@webapplicate.com> | 2021-01-06 08:23:45 -0500 |
---|---|---|
committer | José Padilla <jpadilla@webapplicate.com> | 2021-01-06 08:23:45 -0500 |
commit | 7830c7aa3dd90b3b549bf5a1da57ee4363a6b0ba (patch) | |
tree | 60de746dd37a88c84000fb3a47fd10c7ab8e163a /jwt/algorithms.py | |
parent | 03610f01030e25bd5e901fe625c0ede4c55dccc7 (diff) | |
download | pyjwt-fix-from-jwk.tar.gz |
Fix `from_jwk()` for all algorithmsfix-from-jwk
Diffstat (limited to 'jwt/algorithms.py')
-rw-r--r-- | jwt/algorithms.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/jwt/algorithms.py b/jwt/algorithms.py index 9f16701..0d54382 100644 --- a/jwt/algorithms.py +++ b/jwt/algorithms.py @@ -199,7 +199,15 @@ class HMACAlgorithm(Algorithm): @staticmethod def from_jwk(jwk): - obj = json.loads(jwk) + try: + if isinstance(jwk, str): + obj = json.loads(jwk) + elif isinstance(jwk, dict): + obj = jwk + else: + raise ValueError + except ValueError: + raise InvalidKeyError("Key is not valid JSON") if obj.get("kty") != "oct": raise InvalidKeyError("Not an HMAC key") @@ -424,9 +432,13 @@ if has_crypto: @staticmethod def from_jwk(jwk): - try: - obj = json.loads(jwk) + if isinstance(jwk, str): + obj = json.loads(jwk) + elif isinstance(jwk, dict): + obj = jwk + else: + raise ValueError except ValueError: raise InvalidKeyError("Key is not valid JSON") |