Skip to content

Commit

Permalink
Fixes #1193: deprecated JWT decode.
Browse files Browse the repository at this point in the history
Update to usePyJWT 2.1.0
  • Loading branch information
jensens committed Aug 12, 2021
1 parent 34dc327 commit becdb29
Show file tree
Hide file tree
Showing 60 changed files with 439 additions and 403 deletions.
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
10 changes: 7 additions & 3 deletions src/plone/restapi/pas/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ 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
raise

def _signing_secret(self):
if self.use_keyring:
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
2 changes: 1 addition & 1 deletion src/plone/restapi/tests/http-examples/404_not_found.resp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ HTTP/1.1 404 Not Found
Content-Type: application/json

{
"message": "Resource not found: http://localhost:55001/plone/non-existing-resource",
"message": "Resource not found: http://localhost:50477/plone/non-existing-resource",
"type": "NotFound"
}
20 changes: 10 additions & 10 deletions src/plone/restapi/tests/http-examples/batching.resp
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ HTTP/1.1 200 OK
Content-Type: application/json

{
"@id": "http://localhost:55001/plone/folder/@search",
"@id": "http://localhost:50477/plone/folder/@search",
"batching": {
"@id": "http://localhost:55001/plone/folder/@search?b_size=5&sort_on=path",
"first": "http://localhost:55001/plone/folder/@search?b_start=0&b_size=5&sort_on=path",
"last": "http://localhost:55001/plone/folder/@search?b_start=5&b_size=5&sort_on=path",
"next": "http://localhost:55001/plone/folder/@search?b_start=5&b_size=5&sort_on=path"
"@id": "http://localhost:50477/plone/folder/@search?b_size=5&sort_on=path",
"first": "http://localhost:50477/plone/folder/@search?b_start=0&b_size=5&sort_on=path",
"last": "http://localhost:50477/plone/folder/@search?b_start=5&b_size=5&sort_on=path",
"next": "http://localhost:50477/plone/folder/@search?b_start=5&b_size=5&sort_on=path"
},
"items": [
{
"@id": "http://localhost:55001/plone/folder",
"@id": "http://localhost:50477/plone/folder",
"@type": "Folder",
"description": "",
"review_state": "private",
"title": "Folder"
},
{
"@id": "http://localhost:55001/plone/folder/doc-1",
"@id": "http://localhost:50477/plone/folder/doc-1",
"@type": "Document",
"description": "",
"review_state": "private",
"title": "Document 1"
},
{
"@id": "http://localhost:55001/plone/folder/doc-2",
"@id": "http://localhost:50477/plone/folder/doc-2",
"@type": "Document",
"description": "",
"review_state": "private",
"title": "Document 2"
},
{
"@id": "http://localhost:55001/plone/folder/doc-3",
"@id": "http://localhost:50477/plone/folder/doc-3",
"@type": "Document",
"description": "",
"review_state": "private",
"title": "Document 3"
},
{
"@id": "http://localhost:55001/plone/folder/doc-4",
"@id": "http://localhost:50477/plone/folder/doc-4",
"@type": "Document",
"description": "",
"review_state": "private",
Expand Down
6 changes: 3 additions & 3 deletions src/plone/restapi/tests/http-examples/breadcrumbs.resp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ HTTP/1.1 200 OK
Content-Type: application/json

{
"@id": "http://localhost:55001/plone/front-page/@breadcrumbs",
"@id": "http://localhost:50477/plone/front-page/@breadcrumbs",
"items": [
{
"@id": "http://localhost:55001/plone/front-page",
"@id": "http://localhost:50477/plone/front-page",
"title": "Welcome to Plone"
}
],
"root": "http://localhost:55001/plone"
"root": "http://localhost:50477/plone"
}
26 changes: 13 additions & 13 deletions src/plone/restapi/tests/http-examples/collection.resp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ Content-Type: application/json
{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/collection/@actions"
"@id": "http://localhost:50477/plone/collection/@actions"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/collection/@breadcrumbs"
"@id": "http://localhost:50477/plone/collection/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/collection/@contextnavigation"
"@id": "http://localhost:50477/plone/collection/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/collection/@navigation"
"@id": "http://localhost:50477/plone/collection/@navigation"
},
"types": {
"@id": "http://localhost:55001/plone/collection/@types"
"@id": "http://localhost:50477/plone/collection/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/collection/@workflow"
"@id": "http://localhost:50477/plone/collection/@workflow"
}
},
"@id": "http://localhost:55001/plone/collection",
"@id": "http://localhost:50477/plone/collection",
"@type": "Collection",
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
Expand Down Expand Up @@ -58,21 +58,21 @@ Content-Type: application/json
"item_count": 30,
"items": [
{
"@id": "http://localhost:55001/plone/front-page",
"@id": "http://localhost:50477/plone/front-page",
"@type": "Document",
"description": "Congratulations! You have successfully installed Plone.",
"review_state": "private",
"title": "Welcome to Plone"
},
{
"@id": "http://localhost:55001/plone/doc1",
"@id": "http://localhost:50477/plone/doc1",
"@type": "Document",
"description": "",
"review_state": "private",
"title": "Document 1"
},
{
"@id": "http://localhost:55001/plone/doc2",
"@id": "http://localhost:50477/plone/doc2",
"@type": "Document",
"description": "",
"review_state": "private",
Expand All @@ -85,19 +85,19 @@ Content-Type: application/json
"limit": 1000,
"modified": "1995-07-31T17:30:00",
"next_item": {
"@id": "http://localhost:55001/plone/doc1",
"@id": "http://localhost:50477/plone/doc1",
"@type": "Document",
"description": "",
"title": "Document 1"
},
"parent": {
"@id": "http://localhost:55001/plone",
"@id": "http://localhost:50477/plone",
"@type": "Plone Site",
"description": "",
"title": "Plone site"
},
"previous_item": {
"@id": "http://localhost:55001/plone/front-page",
"@id": "http://localhost:50477/plone/front-page",
"@type": "Document",
"description": "Congratulations! You have successfully installed Plone.",
"title": "Welcome to Plone"
Expand Down
Loading

0 comments on commit becdb29

Please sign in to comment.