mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 20:21:55 +02:00
Resolve "Use cookies instead of local storage for auth in Web UI"
This commit is contained in:
parent
c0055b3b20
commit
c395076fce
18 changed files with 203 additions and 153 deletions
|
@ -1,16 +1,21 @@
|
|||
from asgiref.sync import async_to_sync
|
||||
from channels.generic.websocket import JsonWebsocketConsumer
|
||||
|
||||
from channels import auth
|
||||
from funkwhale_api.common import channels
|
||||
|
||||
|
||||
class JsonAuthConsumer(JsonWebsocketConsumer):
|
||||
def connect(self):
|
||||
try:
|
||||
assert self.scope["user"].pk is not None
|
||||
except (AssertionError, AttributeError, KeyError):
|
||||
return self.close()
|
||||
if "user" not in self.scope:
|
||||
try:
|
||||
self.scope["user"] = async_to_sync(auth.get_user)(self.scope)
|
||||
except (ValueError, AssertionError, AttributeError, KeyError):
|
||||
return self.close()
|
||||
|
||||
return self.accept()
|
||||
if self.scope["user"] and self.scope["user"].is_authenticated:
|
||||
return self.accept()
|
||||
else:
|
||||
return self.close()
|
||||
|
||||
def accept(self):
|
||||
super().accept()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue