Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Dec 4, 2023
1 parent a13ab4c commit 3ec1236
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
29 changes: 23 additions & 6 deletions livekit-api/livekit/api/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import datetime
import os
import jwt
from typing import Optional

DEFAULT_TTL = datetime.timedelta(hours=6)
DEFAULT_LEEWAY = datetime.timedelta(minutes=1)
Expand Down Expand Up @@ -74,14 +75,21 @@ 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:
if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = 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 @@ -137,11 +145,20 @@ 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:
if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = 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
22 changes: 19 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,33 @@
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
):
if not url:
url = os.getenv("LIVEKIT_URL", "")

if not api_key:
api_key = os.getenv("LIVEKIT_API_KEY", "")

if not api_secret:
api_secret = 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 3ec1236

Please sign in to comment.