Skip to content

Commit

Permalink
copying scope before modifying it in JWTMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Aug 13, 2019
1 parent 374b296 commit 3bee368
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ default it's set to 1 day.
expiry=timedelta(minutes=10)
)
.. hint:: You generally want short expiry tokens for web applications, and
longer expiry times for mobile applications.

JWTMiddleware
-------------

Expand Down
6 changes: 4 additions & 2 deletions piccolo_api/middleware/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import typing as t
import time

Expand Down Expand Up @@ -102,6 +103,7 @@ async def __call__(self, scope, receive, send):
if not user_id:
raise HTTPException(status_code=403)

scope['user_id'] = user_id
new_scope = copy.copy(scope)
new_scope['user_id'] = user_id

await self.asgi(scope, receive, send)
await self.asgi(new_scope, receive, send)

0 comments on commit 3bee368

Please sign in to comment.