Skip to content

Commit

Permalink
fix access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Nov 14, 2023
1 parent cf93996 commit 962c721
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -173,7 +176,7 @@ def camel_to_snake(t: str):
return re.sub(r"(?<!^)(?=[A-Z])", "_", t).lower()


def snake_to_lower_camel(s):
def snake_to_lower_camel(t: str):
return "".join(
word.capitalize() if i else word for i, word in enumerate(s.split("_"))
word.capitalize() if i else word for i, word in enumerate(t.split("_"))
)

0 comments on commit 962c721

Please sign in to comment.