From f3d35c72d3dc334d5963d4f9a57137eeacdff873 Mon Sep 17 00:00:00 2001 From: houfu Date: Tue, 18 Jun 2024 22:36:19 +0800 Subject: [PATCH 1/3] Add Anonymous login --- supabase_auth/_sync/gotrue_client.py | 25 ++++++++++++++++++++++++- supabase_auth/types.py | 9 +++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/supabase_auth/_sync/gotrue_client.py b/supabase_auth/_sync/gotrue_client.py index ec8e22f3..672425ee 100644 --- a/supabase_auth/_sync/gotrue_client.py +++ b/supabase_auth/_sync/gotrue_client.py @@ -69,7 +69,7 @@ Subscription, UserAttributes, UserResponse, - VerifyOtpParams, + VerifyOtpParams, SignInAnonymouslyCredentials, ) from .gotrue_admin_api import SyncGoTrueAdminAPI from .gotrue_base_api import SyncGoTrueBaseAPI @@ -337,6 +337,29 @@ def sign_in_with_oauth( url = self._get_url_for_provider(provider, params) return OAuthResponse(provider=provider, url=url) + def sign_in_anonymously(self, credentials: Union[SignInAnonymouslyCredentials]) -> AuthResponse: + """ + Creates a new anonymous user. + """ + self._remove_session() + options = credentials.get("options", {}) + data = options.get("data") or {} + captcha_token = options.get("captcha_token") + response = self._request( + "POST", + "signup", + body={ + "data": data, + "gotrue_meta_security": { + "captcha_token": captcha_token, + }, + } + ) + if response.session: + self._save_session(response.session) + self._notify_all_subscribers("SIGNED_IN", response.session) + return response + def link_identity(self, credentials): provider = credentials.get("provider") options = credentials.get("options", {}) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index ee260b04..56cd7f51 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -348,6 +348,15 @@ class SignInWithSSOOptions(TypedDict): skip_http_redirect: NotRequired[bool] +class SignInAnonymouslyCredentials(TypedDict): + options: NotRequired[SignInAnonymouslySSOOptions] + + +class SignInAnonymouslySSOOptions(TypedDict): + data: NotRequired[Any] + captcha_token: NotRequired[str] + + class VerifyOtpParamsOptions(TypedDict): redirect_to: NotRequired[str] captcha_token: NotRequired[str] From 85f94f27320af3438748fe261a752a29b03a2c24 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 20 Jun 2024 08:21:05 +0000 Subject: [PATCH 2/3] update async client and type naming --- supabase_auth/_async/gotrue_client.py | 30 +++++++++++++++ supabase_auth/_sync/gotrue_client.py | 55 +++++++++++++++------------ supabase_auth/types.py | 4 +- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/supabase_auth/_async/gotrue_client.py b/supabase_auth/_async/gotrue_client.py index 3e93d005..1fe60de7 100644 --- a/supabase_auth/_async/gotrue_client.py +++ b/supabase_auth/_async/gotrue_client.py @@ -61,9 +61,11 @@ Options, Provider, Session, + SignInAnonymouslyCredentials, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, + SignInWithSSOCredentials, SignOutOptions, SignUpWithPasswordCredentials, Subscription, @@ -149,6 +151,34 @@ async def initialize_from_url(self, url: str) -> None: # Public methods + async def sign_in_anonymously( + self, credentials: Union[SignInAnonymouslyCredentials, None] = None + ) -> AuthResponse: + """ + Creates a new anonymous user. + """ + self._remove_session() + if credentials is None: + credentials = {"options": {}} + options = credentials.get("options", {}) + data = options.get("data") or {} + captcha_token = options.get("captcha_token") + response = self._request( + "POST", + "signup", + body={ + "data": data, + "gotrue_meta_security": { + "captcha_token": captcha_token, + }, + }, + xform=parse_auth_response, + ) + if response.session: + self._save_session(response.session) + self._notify_all_subscribers("SIGNED_IN", response.session) + return response + async def sign_up( self, credentials: SignUpWithPasswordCredentials, diff --git a/supabase_auth/_sync/gotrue_client.py b/supabase_auth/_sync/gotrue_client.py index 672425ee..6a8c764f 100644 --- a/supabase_auth/_sync/gotrue_client.py +++ b/supabase_auth/_sync/gotrue_client.py @@ -61,15 +61,17 @@ Options, Provider, Session, + SignInAnonymouslyCredentials, SignInWithOAuthCredentials, SignInWithPasswordCredentials, SignInWithPasswordlessCredentials, + SignInWithSSOCredentials, SignOutOptions, SignUpWithPasswordCredentials, Subscription, UserAttributes, UserResponse, - VerifyOtpParams, SignInAnonymouslyCredentials, + VerifyOtpParams, ) from .gotrue_admin_api import SyncGoTrueAdminAPI from .gotrue_base_api import SyncGoTrueBaseAPI @@ -149,6 +151,34 @@ def initialize_from_url(self, url: str) -> None: # Public methods + def sign_in_anonymously( + self, credentials: Union[SignInAnonymouslyCredentials, None] = None + ) -> AuthResponse: + """ + Creates a new anonymous user. + """ + self._remove_session() + if credentials is None: + credentials = {"options": {}} + options = credentials.get("options", {}) + data = options.get("data") or {} + captcha_token = options.get("captcha_token") + response = self._request( + "POST", + "signup", + body={ + "data": data, + "gotrue_meta_security": { + "captcha_token": captcha_token, + }, + }, + xform=parse_auth_response, + ) + if response.session: + self._save_session(response.session) + self._notify_all_subscribers("SIGNED_IN", response.session) + return response + def sign_up( self, credentials: SignUpWithPasswordCredentials, @@ -337,29 +367,6 @@ def sign_in_with_oauth( url = self._get_url_for_provider(provider, params) return OAuthResponse(provider=provider, url=url) - def sign_in_anonymously(self, credentials: Union[SignInAnonymouslyCredentials]) -> AuthResponse: - """ - Creates a new anonymous user. - """ - self._remove_session() - options = credentials.get("options", {}) - data = options.get("data") or {} - captcha_token = options.get("captcha_token") - response = self._request( - "POST", - "signup", - body={ - "data": data, - "gotrue_meta_security": { - "captcha_token": captcha_token, - }, - } - ) - if response.session: - self._save_session(response.session) - self._notify_all_subscribers("SIGNED_IN", response.session) - return response - def link_identity(self, credentials): provider = credentials.get("provider") options = credentials.get("options", {}) diff --git a/supabase_auth/types.py b/supabase_auth/types.py index 56cd7f51..53877eba 100644 --- a/supabase_auth/types.py +++ b/supabase_auth/types.py @@ -349,10 +349,10 @@ class SignInWithSSOOptions(TypedDict): class SignInAnonymouslyCredentials(TypedDict): - options: NotRequired[SignInAnonymouslySSOOptions] + options: NotRequired[SignInAnonymouslyCredentialsOptions] -class SignInAnonymouslySSOOptions(TypedDict): +class SignInAnonymouslyCredentialsOptions(TypedDict): data: NotRequired[Any] captcha_token: NotRequired[str] From ad2179b1c042c8faf1b1cdc322d8c9f9d5aae9e7 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 20 Jun 2024 08:40:57 +0000 Subject: [PATCH 3/3] update postgres version for infra --- infra/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index dcced8bd..a4cf04c7 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -106,7 +106,7 @@ services: - '9000:9000' # web interface - '1100:1100' # POP3 db: - image: supabase/postgres:latest + image: supabase/postgres:15.1.1.66 ports: - '5432:5432' command: postgres -c config_file=/etc/postgresql/postgresql.conf