Skip to content

Commit

Permalink
token_verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Nov 14, 2023
1 parent eafa9b9 commit f0ce3a4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import jwt

DEFAULT_TTL = datetime.timedelta(hours=6)
DEFAULT_LEEWAY = datetime.timedelta(minutes=1)


@dataclasses.dataclass
Expand Down Expand Up @@ -136,3 +137,23 @@ def camel_case_dict(data) -> dict:
)

return jwt.encode(claims, self.api_secret, algorithm="HS256")


class TokenVerifier:
def __init__(
self,
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
) -> None:
self.api_key = api_key
self.api_secret = api_secret

def verify(self, token: str) -> Claims:
claims = jwt.decode(
token,
self.api_secret,
issuer=self.api_key,
algorithms=["HS256"],
leeway=DEFAULT_LEEWAY.total_seconds(),
)
return claims

0 comments on commit f0ce3a4

Please sign in to comment.