Skip to content

Commit

Permalink
Merge branch 'main' into theo/fix-access-token
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom authored Dec 4, 2023
2 parents 61ec6a0 + 2352d08 commit c1c573e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
24 changes: 17 additions & 7 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import datetime
import os
import jwt
from typing import List
from typing import Optional, List

DEFAULT_TTL = datetime.timedelta(hours=6)
DEFAULT_LEEWAY = datetime.timedelta(minutes=1)
Expand Down Expand Up @@ -75,14 +75,18 @@ class Claims:
class AccessToken:
def __init__(
self,
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
) -> None:
api_key = api_key or os.getenv("LIVEKIT_API_KEY")
api_secret = api_secret or os.getenv("LIVEKIT_API_SECRET")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self.api_key = api_key # iss
self.api_secret = api_secret
self.claims = Claims()
if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

# default jwt claims
self.identity = "" # sub
Expand Down Expand Up @@ -138,11 +142,17 @@ def to_jwt(self) -> str:
class TokenVerifier:
def __init__(
self,
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
*,
leeway: datetime.timedelta = DEFAULT_LEEWAY,
) -> None:
api_key = api_key or os.getenv("LIVEKIT_API_KEY")
api_secret = api_secret or os.getenv("LIVEKIT_API_SECRET")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self.api_key = api_key
self.api_secret = api_secret
self._leeway = leeway
Expand Down
17 changes: 14 additions & 3 deletions livekit-api/livekit/api/livekit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
from .room_service import RoomService
from .egress_service import EgressService
from .ingress_service import IngressService
from typing import Optional


class LiveKitAPI:
def __init__(
self,
url: str = os.getenv("LIVEKIT_URL", "http://localhost:7880"),
api_key: str = os.getenv("LIVEKIT_API_KEY", ""),
api_secret: str = os.getenv("LIVEKIT_API_SECRET", ""),
url: Optional[str] = None,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
*,
timeout: float = 60, # 1 minutes by default
):
url = url or os.getenv("LIVEKIT_URL")
api_key = api_key or os.getenv("LIVEKIT_API_KEY")
api_secret = api_secret or os.getenv("LIVEKIT_API_SECRET")

if not url:
raise ValueError("url must be set")

if not api_key or not api_secret:
raise ValueError("api_key and api_secret must be set")

self._session = aiohttp.ClientSession(timeout=timeout)
self._room = RoomService(url, api_key, api_secret, self._session)
self._ingress = IngressService(url, api_key, api_secret, self._session)
Expand Down

0 comments on commit c1c573e

Please sign in to comment.