calm-rain-75033
10/16/2025, 9:22 AMclass GetLiveKitToken(generics.CreateAPIView):
"""
Get livekit token for a user
"""
# permission_classes = (IsAuthenticated,)
def get(self, request):
try:
# user = "Asim ali"
user_id = 100
user_name = "Asim ali"
# room_id = uuid.uuid4()
token = api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)\
.with_identity(user_id)\
.with_name(user_name)\
.with_grants(
api.VideoGrants(
room_join=True,
room="my room",
can_publish=True,
can_subscribe=True,
can_publish_data=True,
can_publish_sources=["audio", "data"]
)
).with_metadata(json.dumps({
"userId": user_id,
"room_id": "my room",
}))
return Response({"token": token.to_jwt(), "room_id": "my room", "url": LIVEKIT_URL})
except Exception as error:
logger.error(
f"Error getting livekit token for user {user_id}: {str(error)}")
return Response({"error": "Failed to get livekit token"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)tall-airline-16756
10/16/2025, 9:22 AMtall-airline-16756
10/16/2025, 9:23 AMidentity and room, especially if you're using room_join grants.
• Clock Skew: It’s important that your server’s clock is synchronized and falls within the token’s valid time window.
• Incorrect Token Usage Context: Remember, tokens need to be valid at the moment of the initial connection.
• Server-Side Verification: Ensure the server that verifies the token is using the same API key and secret that were used to generate it.
Take a look at these points in your setup, and if anything isn’t clear or if you need more help, please don’t hesitate to reach out. I’m here to support you every step of the way!
Sources: spec/livekit/access_token_spec.rb | livekit-api/src/access_token.rs | livekit-api/livekit/api/access_token.py | Authentication | LiveKit Docs