feat: 优化ws 认证
This commit is contained in:
parent
16490c5907
commit
d5386ccd84
|
@ -15,6 +15,9 @@ class TokenAuthMiddleware:
|
|||
# checking if it is a valid user ID, or if scope["user"] is already
|
||||
# populated).
|
||||
from urllib.parse import parse_qs
|
||||
token = parse_qs(str(scope["query_string"], 'UTF-8'))['token'][0]
|
||||
scope['user'] = await _get_user(token)
|
||||
return await self.app(scope, receive, send)
|
||||
token = parse_qs(str(scope["query_string"], 'UTF-8')).get('token', [None])[0]
|
||||
if token:
|
||||
user = await _get_user(token)
|
||||
if user:
|
||||
scope['user'] = user
|
||||
return await self.app(scope, receive, send)
|
Loading…
Reference in New Issue