You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the great tutorial! One thing that I had hoped could be improved is that a standard middleware could be used for token auth rather than having to implement this in each app.
channels-auth-token-middlewares recently added support for this in a standard way that can be reused, so I thought perhaps TestDriven IO might be interested in using that for the training tutorials.
INSTALLED_APPS= [
# base django apps (django.contrib.auth is required)# other apps this one depends on (like rest_framework if it's necessary)'channels_auth_token_middlewares',
# custom apps
]
The authenticated User (or AnonymousUser if the JWT is invalid) will be populated into the "user" key of the scope passed to the Consumer
classMyAsyncCommunicator(AsyncWebsocketConsumer):
asyncdefconnect(self) ->None:
user=self.scope["user"]
# Validate user before accepting the Websocket Connection# For example:ifnotuser.is_authenticatedoruser.is_anonymous:
# Handle unauthorized.
The text was updated successfully, but these errors were encountered:
Thanks for the great tutorial! One thing that I had hoped could be improved is that a standard middleware could be used for token auth rather than having to implement this in each app.
channels-auth-token-middlewares
recently added support for this in a standard way that can be reused, so I thought perhaps TestDriven IO might be interested in using that for the training tutorials.channels-auth-token-middlewares
provides aQueryStringSimpleJWTAuthTokenMiddleware
to support token authentication out of the box when using Simple JWT with Django REST Framework.Update
INSTALLED_APPS
:Insert
QueryStringSimpleJWTAuthTokenMiddleware
into your ASGIapplication
stack:Clients pass their JWT token into the
token
query parameter:The authenticated
User
(orAnonymousUser
if the JWT is invalid) will be populated into the"user"
key of thescope
passed to theConsumer
The text was updated successfully, but these errors were encountered: