Skip to content

Commit 7d0ab18

Browse files
committed
fix(api): inline jwt decode options for mypy Options
A shared options dict from a ternary widens to dict[str, object] and fails livekit-api type-check against PyJWT Options.
1 parent ab56856 commit 7d0ab18

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

livekit-api/livekit/api/access_token.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,26 @@ def verify(self, token: str, *, verify_signature: bool = True) -> Claims:
235235

236236
# First-party minters always set exp. Without this, a hand-rolled token
237237
# with a valid signature and no exp verifies forever (livekit/protocol#1706).
238-
decode_options = (
239-
{"verify_signature": True, "require": ["exp"]}
240-
if verify_signature
241-
else {"verify_signature": False}
242-
)
243-
244-
claims = jwt.decode(
245-
token,
246-
key=self.api_secret or "",
247-
issuer=self.api_key or "",
248-
algorithms=["HS256"],
249-
leeway=self._leeway.total_seconds(),
250-
options=decode_options,
251-
)
238+
# Inline each options literal so mypy matches PyJWT's Options TypedDict
239+
# (a shared dict from a ternary widens to dict[str, object]).
240+
if verify_signature:
241+
claims = jwt.decode(
242+
token,
243+
key=self.api_secret or "",
244+
issuer=self.api_key or "",
245+
algorithms=["HS256"],
246+
leeway=self._leeway.total_seconds(),
247+
options={"verify_signature": True, "require": ["exp"]},
248+
)
249+
else:
250+
claims = jwt.decode(
251+
token,
252+
key=self.api_secret or "",
253+
issuer=self.api_key or "",
254+
algorithms=["HS256"],
255+
leeway=self._leeway.total_seconds(),
256+
options={"verify_signature": False},
257+
)
252258
video_dict = claims.get("video", dict())
253259
video_dict = {camel_to_snake(k): v for k, v in video_dict.items()}
254260
video_dict = {k: v for k, v in video_dict.items() if k in VideoGrants.__dataclass_fields__}

0 commit comments

Comments
 (0)