Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion authentik/core/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ def user_logged_in_session(sender, request: HttpRequest, user: User, **_):

if not RefreshOtherFlowsAfterAuthentication().get():
return
LOGGER.debug("Sending authenticated signal")
layer = get_channel_layer()
device_cookie = request.COOKIES.get("authentik_device")
if device_cookie:
group = build_device_group(device_cookie)
LOGGER.debug("Sending signal to group", group=group)
async_to_sync(layer.group_send)(
build_device_group(device_cookie),
group,
{"type": "event.session.authenticated"},
)

Expand Down
15 changes: 9 additions & 6 deletions authentik/root/ws/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
from channels.generic.websocket import JsonWebsocketConsumer
from django.core.cache import cache
from django.db import connection
from structlog.stdlib import get_logger

from authentik.root.ws.storage import CACHE_PREFIX

LOGGER = get_logger()


def build_session_group(session_key: str):
return sha256(
Expand Down Expand Up @@ -36,17 +39,17 @@ def connect(self):
cache.set(f"{CACHE_PREFIX}{self.session_key}_messages_{self.channel_name}", True, None)
if device_cookie := self.scope["cookies"].get("authentik_device", None):
self.device_cookie = device_cookie
async_to_sync(self.channel_layer.group_add)(
build_device_group(self.device_cookie), self.channel_name
)
group = build_device_group(self.device_cookie)
LOGGER.debug("Joining device group", group=group)
async_to_sync(self.channel_layer.group_add)(group, self.channel_name)

def disconnect(self, code):
if self.session_key:
cache.delete(f"{CACHE_PREFIX}{self.session_key}_messages_{self.channel_name}")
if self.device_cookie:
async_to_sync(self.channel_layer.group_discard)(
build_device_group(self.device_cookie), self.channel_name
)
group = build_device_group(self.device_cookie)
LOGGER.debug("Leaving device group", group=group)
async_to_sync(self.channel_layer.group_discard)(group, self.channel_name)

def event_message(self, event: dict):
"""Event handler which is called by Messages Storage backend"""
Expand Down
Loading