diff --git a/src/backend/core/api/serializers.py b/src/backend/core/api/serializers.py index d9420ee4..1537b805 100644 --- a/src/backend/core/api/serializers.py +++ b/src/backend/core/api/serializers.py @@ -184,6 +184,7 @@ class RoomSerializer(serializers.ModelSerializer): username=username, configuration=output["configuration"], role=role, + is_authenticated=request.user.is_authenticated, ) else: del output["pin_code"] diff --git a/src/backend/core/tests/rooms/test_api_rooms_retrieve.py b/src/backend/core/tests/rooms/test_api_rooms_retrieve.py index d27b13bf..ff746062 100644 --- a/src/backend/core/tests/rooms/test_api_rooms_retrieve.py +++ b/src/backend/core/tests/rooms/test_api_rooms_retrieve.py @@ -12,7 +12,7 @@ import pytest from rest_framework.test import APIClient from ...factories import RoomFactory, UserFactory, UserResourceAccessFactory -from ...models import RoomAccessLevel, RoleChoices +from ...models import RoleChoices, RoomAccessLevel pytestmark = pytest.mark.django_db @@ -280,6 +280,7 @@ def test_api_rooms_retrieve_authenticated_public(mock_token): sources=["camera"], role=None, participant_id=None, + is_authenticated=True, ) @@ -332,6 +333,7 @@ def test_api_rooms_retrieve_authenticated_trusted(mock_token): sources=None, role=None, participant_id=None, + is_authenticated=True, ) @@ -420,6 +422,7 @@ def test_api_rooms_retrieve_members(mock_token, django_assert_num_queries, setti sources=["camera"], role=str(RoleChoices.MEMBER), participant_id=None, + is_authenticated=True, ) @@ -513,4 +516,5 @@ def test_api_rooms_retrieve_administrators( sources=None, role=str(user_access.role), participant_id=None, + is_authenticated=True, ) diff --git a/src/backend/core/utils.py b/src/backend/core/utils.py index 02d609c2..abfce2ce 100644 --- a/src/backend/core/utils.py +++ b/src/backend/core/utils.py @@ -68,6 +68,7 @@ def generate_token( sources: Optional[List[str]] = None, role: Optional[str] = None, participant_id: Optional[str] = None, + is_authenticated: Optional[bool] = False, ) -> str: """Generate a LiveKit access token for a user in a specific room. @@ -83,6 +84,7 @@ def generate_token( role (Optional[str]): Room's access role if any participant_id (Optional[str]): Stable identifier for anonymous users; used as identity when user.is_anonymous. + is_authenticated (Optional[bool]): Is user authentified. Returns: str: The LiveKit JWT access token. @@ -129,7 +131,7 @@ def generate_token( .with_identity(identity) .with_name(display_name) .with_attributes( - {"color": color, "room_role": role } + {"color": color, "room_role": role, "is_authenticated": 'true' if is_authenticated else 'false'} ) ) @@ -144,6 +146,7 @@ def generate_livekit_config( color: Optional[str] = None, configuration: Optional[dict] = None, participant_id: Optional[str] = None, + is_authenticated: Optional[bool] = False, ) -> dict: """Generate LiveKit configuration for room access. @@ -156,6 +159,7 @@ def generate_livekit_config( configuration (Optional[dict]): Room configuration dict that can override default settings. participant_id (Optional[str]): Stable identifier for anonymous users; used as identity when user.is_anonymous. + is_authenticated: Optional[bool]: Is user authentified. Returns: dict: LiveKit configuration with URL, room and access token @@ -176,6 +180,7 @@ def generate_livekit_config( sources=sources, role=role, participant_id=participant_id, + is_authenticated=is_authenticated, ), } diff --git a/src/frontend/src/features/rooms/utils/getParticipantIsAuthenticated.ts b/src/frontend/src/features/rooms/utils/getParticipantIsAuthenticated.ts new file mode 100644 index 00000000..9b55dcde --- /dev/null +++ b/src/frontend/src/features/rooms/utils/getParticipantIsAuthenticated.ts @@ -0,0 +1,8 @@ +import type { Participant } from 'livekit-client' + +export const getParticipantIsAuthenticated = ( + participant: Participant +): boolean => { + const isAuthenticated = participant.attributes?.is_authenticated + return isAuthenticated == 'true' +}