diff --git a/authentik/core/signals.py b/authentik/core/signals.py index 3ebda21be631..d989b1517c31 100644 --- a/authentik/core/signals.py +++ b/authentik/core/signals.py @@ -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"}, ) diff --git a/authentik/root/ws/consumer.py b/authentik/root/ws/consumer.py index 397c439e7f2b..3c8e3b2a1fff 100644 --- a/authentik/root/ws/consumer.py +++ b/authentik/root/ws/consumer.py @@ -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( @@ -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"""