Skip to content

Commit

Permalink
Fix from_jwk() for all algorithms (#598)
Browse files Browse the repository at this point in the history
* Fix `from_jwk()` for all algorithms

* Update CHANGELOG.rst
  • Loading branch information
jpadilla authored Jan 12, 2021
1 parent fdfd687 commit 9dca8ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changed
~~~~~~~

- Rename CHANGELOG.md to CHANGELOG.rst and include in docs `#597 <https://github.com/jpadilla/pyjwt/pull/597>`__
- Fix `from_jwk()` for all algorithms `#598 <https://github.com/jpadilla/pyjwt/pull/598>`__

Fixed
~~~~~
Expand Down
18 changes: 15 additions & 3 deletions jwt/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ def to_jwk(key_obj):

@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")
Expand Down Expand Up @@ -424,9 +432,13 @@ def verify(self, msg, key, sig):

@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")

Expand Down

0 comments on commit 9dca8ea

Please sign in to comment.