From 962c7214f35c149b19d42779c73141c4906d129d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Mon, 13 Nov 2023 22:38:36 -0800 Subject: [PATCH] fix access_token --- livekit-api/livekit/api/access_token.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/livekit-api/livekit/api/access_token.py b/livekit-api/livekit/api/access_token.py index 0683cbc9..e689df46 100644 --- a/livekit-api/livekit/api/access_token.py +++ b/livekit-api/livekit/api/access_token.py @@ -116,8 +116,10 @@ def to_jwt(self) -> str: if video.room_join and (not self.identity or not video.room): raise ValueError("identity and room must be set when joining a room") - claims = dataclasses.asdict(self.claims) - claims = {snake_to_lower_camel(k): v for k, v in claims.items()} + claims = dataclasses.asdict( + self.claims, + dict_factory=lambda items: {snake_to_lower_camel(k): v for k, v in items}, + ) claims.update( { "sub": self.identity, @@ -153,9 +155,10 @@ def verify(self, token: str) -> Claims: leeway=self._leeway.total_seconds(), ) - video_dict = {camel_to_snake(k): v for k, v in claims["video"].items()} - video_dict = {k: v for k, v in video_dict.items() if k in VideoGrants.__dataclass_fields__} + video_dict = { + k: v for k, v in video_dict.items() if k in VideoGrants.__dataclass_fields__ + } video = VideoGrants(**video_dict) c = Claims( @@ -173,7 +176,7 @@ def camel_to_snake(t: str): return re.sub(r"(?