mirror of
https://github.com/suitenumerique/meet.git
synced 2026-07-26 11:58:53 +00:00
✨(backend) expose is_authenticated in the LiveKit token
Include the is_authenticated flag on the user in the LiveKit token and participant metadata. The frontend needs this information (used in the next commit) to know whether it can offer to promote a user with access to the room admin.
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
}
|
||||
Reference in New Issue
Block a user