Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Check if url is an HTTP URL #620

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion supabase_auth/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ..constants import COOKIE_OPTIONS, DEFAULT_HEADERS, GOTRUE_URL, STORAGE_KEY
from ..exceptions import APIError
from ..helpers import model_dump, model_validate
from ..helpers import is_http_url, model_dump, model_validate
from ..types import (
AuthChangeEvent,
CookieOptions,
Expand Down Expand Up @@ -61,6 +61,8 @@ def __init__(
proxy: str
HTTP Proxy string or None, None by default, None disables proxy.
"""
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
if url.startswith("http://"):
print(
"Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOTRUE EVER!\n"
Expand Down Expand Up @@ -428,6 +430,8 @@ def get_session_from_url(
APIError
If an error occurs.
"""
if not is_http_url(url):
ValueError("url must be a valid HTTP URL string")
data = urlparse(url)
query = parse_qs(data.query)
error_description = query.get("error_description")
Expand Down
5 changes: 5 additions & 0 deletions supabase_auth/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime
from json import loads
from typing import Any, Dict, Optional, Type, TypeVar, cast
from urllib.parse import urlparse

from httpx import HTTPStatusError, Response
from pydantic import BaseModel
Expand Down Expand Up @@ -238,3 +239,7 @@ def parse_response_api_version(response: Response):
return dt
except Exception as e:
return None


def is_http_url(url: str) -> bool:
return urlparse(url).scheme in {"https", "http"}