Skip to content

Commit 1886f4e

Browse files
committed
attempting to fix ws auth
1 parent 005f846 commit 1886f4e

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

chats/middleware.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ def get_user(scope):
8484
"TokenAuthMiddleware."
8585
)
8686
token = scope["token"]
87-
user = None
88-
try:
89-
auth = TokenAuthentication()
90-
user = auth.authenticate(token)
91-
except AuthenticationFailed:
92-
pass
87+
# user = None
88+
# try:
89+
auth = TokenAuthentication()
90+
user = auth.authenticate(token)
91+
# except AuthenticationFailed:
92+
# pass
9393
return user or AnonymousUser()
9494

9595

@@ -107,22 +107,21 @@ async def __call__(self, scope, receive, send):
107107
# checking if it is a valid user ID, or if scope["user"] is already
108108
# populated).
109109
headers = scope["headers"]
110-
try:
111-
token = None
112-
for name, value in headers:
113-
if name == b"authorization":
114-
token = value.decode()
115-
break
116-
117-
if token is None:
118-
raise ValueError("Token is missing from headers")
119-
120-
scope["token"] = token
121-
scope["user"] = await get_user(scope)
122-
except ValueError:
123-
# Token is missing from headers
124-
from django.contrib.auth.models import AnonymousUser
125-
126-
scope["user"] = AnonymousUser()
110+
token = None
111+
for name, value in headers:
112+
if name == b"authorization":
113+
token = value.decode()
114+
break
115+
116+
if token is None:
117+
raise ValueError("Token is missing from headers")
118+
119+
scope["token"] = token
120+
scope["user"] = await get_user(scope)
121+
# Token is missing from headers
122+
# if token is None:
123+
# from django.contrib.auth.models import AnonymousUser
124+
#
125+
# scope["user"] = AnonymousUser()
127126

128127
return await self.app(scope, receive, send)

0 commit comments

Comments
 (0)