Skip to content

Commit

Permalink
Fix 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 12, 2021
1 parent 34dc327 commit 5e1a135
Show file tree
Hide file tree
Showing 59 changed files with 437 additions and 401 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
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
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
76 changes: 38 additions & 38 deletions src/plone/restapi/tests/http-examples/collection_fullobjects.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 @@ -60,25 +60,25 @@ Content-Type: application/json
{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/front-page/@actions"
"@id": "http://localhost:50477/plone/front-page/@actions"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/front-page/@breadcrumbs"
"@id": "http://localhost:50477/plone/front-page/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/front-page/@contextnavigation"
"@id": "http://localhost:50477/plone/front-page/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/front-page/@navigation"
"@id": "http://localhost:50477/plone/front-page/@navigation"
},
"types": {
"@id": "http://localhost:55001/plone/front-page/@types"
"@id": "http://localhost:50477/plone/front-page/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/front-page/@workflow"
"@id": "http://localhost:50477/plone/front-page/@workflow"
}
},
"@id": "http://localhost:55001/plone/front-page",
"@id": "http://localhost:50477/plone/front-page",
"@type": "Document",
"UID": "SomeUUID000000000000000000000001",
"allow_discussion": false,
Expand All @@ -98,13 +98,13 @@ Content-Type: application/json
"layout": "document_view",
"modified": "1995-07-31T17:30:00",
"next_item": {
"@id": "http://localhost:55001/plone/collection",
"@id": "http://localhost:50477/plone/collection",
"@type": "Collection",
"description": "This is a collection with two documents",
"title": "My Collection"
},
"parent": {
"@id": "http://localhost:55001/plone",
"@id": "http://localhost:50477/plone",
"@type": "Plone Site",
"description": "",
"title": "Plone site"
Expand All @@ -129,25 +129,25 @@ Content-Type: application/json
{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/doc1/@actions"
"@id": "http://localhost:50477/plone/doc1/@actions"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/doc1/@breadcrumbs"
"@id": "http://localhost:50477/plone/doc1/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/doc1/@contextnavigation"
"@id": "http://localhost:50477/plone/doc1/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/doc1/@navigation"
"@id": "http://localhost:50477/plone/doc1/@navigation"
},
"types": {
"@id": "http://localhost:55001/plone/doc1/@types"
"@id": "http://localhost:50477/plone/doc1/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/doc1/@workflow"
"@id": "http://localhost:50477/plone/doc1/@workflow"
}
},
"@id": "http://localhost:55001/plone/doc1",
"@id": "http://localhost:50477/plone/doc1",
"@type": "Document",
"UID": "SomeUUID000000000000000000000003",
"allow_discussion": false,
Expand All @@ -167,19 +167,19 @@ Content-Type: application/json
"layout": "document_view",
"modified": "1995-07-31T17:30:00",
"next_item": {
"@id": "http://localhost:55001/plone/doc2",
"@id": "http://localhost:50477/plone/doc2",
"@type": "Document",
"description": "",
"title": "Document 2"
},
"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/collection",
"@id": "http://localhost:50477/plone/collection",
"@type": "Collection",
"description": "This is a collection with two documents",
"title": "My Collection"
Expand All @@ -199,25 +199,25 @@ Content-Type: application/json
{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/doc2/@actions"
"@id": "http://localhost:50477/plone/doc2/@actions"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/doc2/@breadcrumbs"
"@id": "http://localhost:50477/plone/doc2/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/doc2/@contextnavigation"
"@id": "http://localhost:50477/plone/doc2/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/doc2/@navigation"
"@id": "http://localhost:50477/plone/doc2/@navigation"
},
"types": {
"@id": "http://localhost:55001/plone/doc2/@types"
"@id": "http://localhost:50477/plone/doc2/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/doc2/@workflow"
"@id": "http://localhost:50477/plone/doc2/@workflow"
}
},
"@id": "http://localhost:55001/plone/doc2",
"@id": "http://localhost:50477/plone/doc2",
"@type": "Document",
"UID": "SomeUUID000000000000000000000004",
"allow_discussion": false,
Expand All @@ -238,13 +238,13 @@ Content-Type: application/json
"modified": "1995-07-31T17:30:00",
"next_item": {},
"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/doc1",
"@id": "http://localhost:50477/plone/doc1",
"@type": "Document",
"description": "",
"title": "Document 1"
Expand All @@ -268,19 +268,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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
HTTP/1.1 204 No Content
Location: http://localhost:55001/plone/front-page/@comments/123456
Location: http://localhost:50477/plone/front-page/@comments/123456

Loading

0 comments on commit 5e1a135

Please sign in to comment.