Basic channels middleware for token auth

This commit is contained in:
Eliot Berriot 2018-02-25 13:05:29 +01:00
parent 498aa1137b
commit 5c2ddc56c4
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
5 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,11 @@
from channels.generic.websocket import JsonWebsocketConsumer
class JsonAuthConsumer(JsonWebsocketConsumer):
def connect(self):
try:
assert self.scope['user'].pk is not None
except (AssertionError, AttributeError, KeyError):
return self.close()
return self.accept()