Skip to content

Commit af63482

Browse files
authored
fix: remove jwt key validation to allow new api keys (#612)
1 parent e4c5eb1 commit af63482

File tree

2 files changed

+1
-29
lines changed

2 files changed

+1
-29
lines changed

postgrest/base_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from httpx import AsyncClient, BasicAuth, Client, Timeout
77

8-
from .utils import is_http_url, is_valid_jwt
8+
from .utils import is_http_url
99

1010

1111
class BasePostgrestClient(ABC):
@@ -71,8 +71,6 @@ def auth(
7171
Bearer token is preferred if both ones are provided.
7272
"""
7373
if token:
74-
if not is_valid_jwt(token):
75-
ValueError("token must be a valid JWT authorization token")
7674
self.session.headers["Authorization"] = f"Bearer {token}"
7775
elif username:
7876
self.session.auth = BasicAuth(username, password)

postgrest/utils.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import re
43
from typing import Any, Type, TypeVar, cast, get_origin
54
from urllib.parse import urlparse
65

@@ -11,8 +10,6 @@
1110

1211
from .version import __version__
1312

14-
BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
15-
1613

1714
class SyncClient(BaseClient):
1815
@deprecated(
@@ -61,29 +58,6 @@ def is_http_url(url: str) -> bool:
6158
return urlparse(url).scheme in {"https", "http"}
6259

6360

64-
def is_valid_jwt(value: str) -> bool:
65-
"""Checks if value looks like a JWT, does not do any extra parsing."""
66-
if not isinstance(value, str):
67-
return False
68-
69-
# Remove trailing whitespaces if any.
70-
value = value.strip()
71-
72-
# Remove "Bearer " prefix if any.
73-
if value.startswith("Bearer "):
74-
value = value[7:]
75-
76-
# Valid JWT must have 2 dots (Header.Paylod.Signature)
77-
if value.count(".") != 2:
78-
return False
79-
80-
for part in value.split("."):
81-
if not re.search(BASE64URL_REGEX, part, re.IGNORECASE):
82-
return False
83-
84-
return True
85-
86-
8761
TBaseModel = TypeVar("TBaseModel", bound=BaseModel)
8862

8963

0 commit comments

Comments
 (0)