Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 78705e2

Browse files
authored
fix: remove jwt validation to allow new api keys (#322)
1 parent 32d2daf commit 78705e2

File tree

2 files changed

+0
-37
lines changed

2 files changed

+0
-37
lines changed

realtime/_async/client.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import json
33
import logging
44
import re
5-
from base64 import b64decode
6-
from datetime import datetime
75
from functools import wraps
8-
from math import floor
96
from typing import Any, Callable, Dict, List, Optional
107
from urllib.parse import urlencode, urlparse, urlunparse
118

@@ -316,30 +313,6 @@ async def set_auth(self, token: Optional[str]) -> None:
316313
Returns:
317314
None
318315
"""
319-
# No empty string tokens.
320-
if isinstance(token, str) and len(token.strip()) == 0:
321-
raise ValueError("Provide a valid jwt token")
322-
323-
if token:
324-
parsed = None
325-
try:
326-
payload = token.split(".")[1] + "=="
327-
parsed = json.loads(b64decode(payload).decode("utf-8"))
328-
except Exception:
329-
raise ValueError("InvalidJWTToken")
330-
331-
if parsed:
332-
# Handle expired token if any.
333-
if "exp" in parsed:
334-
now = floor(datetime.now().timestamp())
335-
valid = now - parsed["exp"] < 0
336-
if not valid:
337-
raise ValueError(
338-
f"InvalidJWTToken: Invalid value for JWT claim 'exp' with value { parsed['exp'] }"
339-
)
340-
else:
341-
raise ValueError("InvalidJWTToken: expected claim 'exp'")
342-
343316
self.access_token = token
344317

345318
for _, channel in self.channels.items():

tests/test_connection.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ def test_init_client():
6161
assert client.timeout == DEFAULT_TIMEOUT
6262

6363

64-
@pytest.mark.asyncio
65-
async def test_set_auth_with_invalid_jwt(socket: AsyncRealtimeClient):
66-
await socket.connect()
67-
68-
with pytest.raises(ValueError):
69-
await socket.set_auth("jwt") # Invalid JWT.
70-
71-
await socket.close()
72-
73-
7464
@pytest.mark.asyncio
7565
async def test_broadcast_events(socket: AsyncRealtimeClient):
7666
await socket.connect()

0 commit comments

Comments
 (0)