Skip to content

Commit

Permalink
Fix #1193 - deprecated JWT decode. Update to usePyJWT 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Aug 30, 2021
1 parent 6f220be commit e04d254
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions news/1193.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes deprecated JWT `decode`usage.
Uses and requires latest PyJWT 2.1.0 now.
[jensens]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def read(filename):
"plone.behavior>=1.1", # adds name to behavior directive
"plone.rest >= 1.0a6", # json renderer moved to plone.restapi
"plone.schema >= 1.2.1", # new/fixed json field
"PyJWT",
"PyJWT>=2",
"pytz",
],
extras_require={"test": TEST_REQUIRES},
Expand Down
8 changes: 6 additions & 2 deletions src/plone/restapi/pas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ def _jwt_decode(self, token, secret, verify=True):
if isinstance(token, str):
token = token.encode("utf-8")
try:
return jwt.decode(token, secret, verify=verify, algorithms=["HS256"])
return jwt.decode(
token,
secret,
options={"verify_signature": verify},
algorithms=["HS256"],
)
except jwt.InvalidTokenError:
pass

Expand Down Expand Up @@ -194,7 +199,6 @@ def create_token(self, userid, timeout=None, data=None):
if data is not None:
payload.update(data)
token = jwt.encode(payload, self._signing_secret(), algorithm="HS256")
token = token.decode("utf-8")
if self.store_tokens:
if self._tokens is None:
self._tokens = OOBTree()
Expand Down
5 changes: 4 additions & 1 deletion versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ cffi = 1.14.4

# requirement for json widget tests to pass
plone.schema = 1.3.0
plone.dexterity = 2.9.8
plone.dexterity = 2.9.8

# recent pyjwt
pyjwt = 2.1.0

0 comments on commit e04d254

Please sign in to comment.