diff --git a/authentik/core/api/authenticated_sessions.py b/authentik/core/api/authenticated_sessions.py index 3a5eab649..d06d8d130 100644 --- a/authentik/core/api/authenticated_sessions.py +++ b/authentik/core/api/authenticated_sessions.py @@ -1,6 +1,8 @@ """AuthenticatedSessions API Viewset""" from guardian.utils import get_anonymous_user from rest_framework import mixins +from rest_framework.fields import SerializerMethodField +from rest_framework.request import Request from rest_framework.serializers import ModelSerializer from rest_framework.viewsets import GenericViewSet @@ -10,11 +12,19 @@ from authentik.core.models import AuthenticatedSession class AuthenticatedSessionSerializer(ModelSerializer): """AuthenticatedSession Serializer""" + current = SerializerMethodField() + + def get_current(self, instance: AuthenticatedSession) -> bool: + """Check if session is currently active session""" + request: Request = self.context["request"] + return request._request.session.session_key == instance.session_key + class Meta: model = AuthenticatedSession fields = [ "uuid", + "current", "user", "last_ip", "last_user_agent", diff --git a/schema.yml b/schema.yml index a73c9d5c2..08f6365c5 100644 --- a/schema.yml +++ b/schema.yml @@ -15569,6 +15569,9 @@ components: uuid: type: string format: uuid + current: + type: boolean + readOnly: true user: type: integer last_ip: @@ -15583,6 +15586,7 @@ components: type: string format: date-time required: + - current - last_ip - last_used - user