Skip to content

Commit

Permalink
feat: Proxy support (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco authored Sep 28, 2024
1 parent c865a98 commit 574d615
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion supabase_auth/_async/gotrue_admin_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import partial
from typing import Dict, List, Union
from typing import Dict, List, Optional, Union

from ..helpers import model_validate, parse_link_response, parse_user_response
from ..http_clients import AsyncClient
Expand Down Expand Up @@ -30,13 +30,15 @@ def __init__(
headers: Dict[str, str] = {},
http_client: Union[AsyncClient, None] = None,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
AsyncGoTrueBaseAPI.__init__(
self,
url=url,
headers=headers,
http_client=http_client,
verify=verify,
proxy=proxy,
)
self.mfa = AsyncGoTrueAdminMFAAPI()
self.mfa.list_factors = self._list_factors
Expand Down
4 changes: 3 additions & 1 deletion supabase_auth/_async/gotrue_base_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Callable, Dict, TypeVar, Union, overload
from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload

from httpx import Response
from pydantic import BaseModel
Expand All @@ -21,11 +21,13 @@ def __init__(
headers: Dict[str, str],
http_client: Union[AsyncClient, None],
verify: bool = True,
proxy: Optional[str] = None,
):
self._url = url
self._headers = headers
self._http_client = http_client or AsyncClient(
verify=bool(verify),
proxy=proxy,
follow_redirects=True,
http2=True,
)
Expand Down
4 changes: 3 additions & 1 deletion supabase_auth/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from functools import partial
from json import loads
from time import time
from typing import Callable, Dict, List, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union
from urllib.parse import parse_qs, urlencode, urlparse
from uuid import uuid4

Expand Down Expand Up @@ -96,13 +96,15 @@ def __init__(
http_client: Union[AsyncClient, None] = None,
flow_type: AuthFlowType = "implicit",
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
AsyncGoTrueBaseAPI.__init__(
self,
url=url or GOTRUE_URL,
headers=headers or DEFAULT_HEADERS,
http_client=http_client,
verify=verify,
proxy=proxy,
)
self._storage_key = storage_key or STORAGE_KEY
self._auto_refresh_token = auto_refresh_token
Expand Down
2 changes: 2 additions & 0 deletions supabase_auth/_sync/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def __init__(
cookie_options: CookieOptions,
http_client: Optional[SyncClient] = None,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
"""Initialise API class."""
self.url = url
self.headers = headers
self.cookie_options = cookie_options
self.http_client = http_client or SyncClient(
verify=bool(verify),
proxy=proxy,
follow_redirects=True,
http2=True,
)
Expand Down
4 changes: 4 additions & 0 deletions supabase_auth/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
api: Optional[SyncGoTrueAPI] = None,
replace_default_headers: bool = False,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
"""Create a new client
Expand All @@ -57,6 +58,8 @@ def __init__(
The options for the cookie.
verify: bool
Verify SSL, True by default, False disables verification.
proxy: str
HTTP Proxy string or None, None by default, None disables proxy.
"""
if url.startswith("http://"):
print(
Expand All @@ -76,6 +79,7 @@ def __init__(
"headers": {**empty_or_default_headers, **headers},
"cookie_options": cookie_options,
"verify": verify,
"proxy": proxy,
}
self.api = api or SyncGoTrueAPI(**args)

Expand Down
4 changes: 3 additions & 1 deletion supabase_auth/_sync/gotrue_admin_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import partial
from typing import Dict, List, Union
from typing import Dict, List, Optional, Union

from ..helpers import model_validate, parse_link_response, parse_user_response
from ..http_clients import SyncClient
Expand Down Expand Up @@ -30,13 +30,15 @@ def __init__(
headers: Dict[str, str] = {},
http_client: Union[SyncClient, None] = None,
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
SyncGoTrueBaseAPI.__init__(
self,
url=url,
headers=headers,
http_client=http_client,
verify=verify,
proxy=proxy,
)
self.mfa = SyncGoTrueAdminMFAAPI()
self.mfa.list_factors = self._list_factors
Expand Down
4 changes: 3 additions & 1 deletion supabase_auth/_sync/gotrue_base_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Callable, Dict, TypeVar, Union, overload
from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload

from httpx import Response
from pydantic import BaseModel
Expand All @@ -21,11 +21,13 @@ def __init__(
headers: Dict[str, str],
http_client: Union[SyncClient, None],
verify: bool = True,
proxy: Optional[str] = None,
):
self._url = url
self._headers = headers
self._http_client = http_client or SyncClient(
verify=bool(verify),
proxy=proxy,
follow_redirects=True,
http2=True,
)
Expand Down
4 changes: 3 additions & 1 deletion supabase_auth/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from functools import partial
from json import loads
from time import time
from typing import Callable, Dict, List, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union
from urllib.parse import parse_qs, urlencode, urlparse
from uuid import uuid4

Expand Down Expand Up @@ -96,13 +96,15 @@ def __init__(
http_client: Union[SyncClient, None] = None,
flow_type: AuthFlowType = "implicit",
verify: bool = True,
proxy: Optional[str] = None,
) -> None:
SyncGoTrueBaseAPI.__init__(
self,
url=url or GOTRUE_URL,
headers=headers or DEFAULT_HEADERS,
http_client=http_client,
verify=verify,
proxy=proxy,
)
self._storage_key = storage_key or STORAGE_KEY
self._auto_refresh_token = auto_refresh_token
Expand Down

0 comments on commit 574d615

Please sign in to comment.