supabase_auth 2.7.0__tar.gz → 2.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/LICENSE +1 -1
  2. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/PKG-INFO +1 -1
  3. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/pyproject.toml +3 -3
  4. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/gotrue_admin_api.py +2 -2
  5. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/gotrue_client.py +75 -8
  6. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/gotrue_admin_api.py +2 -2
  7. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/gotrue_client.py +75 -8
  8. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/types.py +52 -4
  9. supabase_auth-2.8.0/supabase_auth/version.py +1 -0
  10. supabase_auth-2.7.0/supabase_auth/version.py +0 -1
  11. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/README.md +0 -0
  12. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/__init__.py +0 -0
  13. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/__init__.py +0 -0
  14. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/gotrue_admin_mfa_api.py +0 -0
  15. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/gotrue_base_api.py +0 -0
  16. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/gotrue_mfa_api.py +0 -0
  17. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_async/storage.py +0 -0
  18. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/__init__.py +0 -0
  19. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/api.py +0 -0
  20. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/client.py +0 -0
  21. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/gotrue_admin_mfa_api.py +0 -0
  22. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/gotrue_base_api.py +0 -0
  23. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/gotrue_mfa_api.py +0 -0
  24. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/_sync/storage.py +0 -0
  25. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/constants.py +0 -0
  26. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/errors.py +0 -0
  27. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/helpers.py +0 -0
  28. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/http_clients.py +0 -0
  29. {supabase_auth-2.7.0 → supabase_auth-2.8.0}/supabase_auth/timer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Joel Lee
3
+ Copyright (c) 2020 Supabase
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supabase_auth
3
- Version: 2.7.0
3
+ Version: 2.8.0
4
4
  Summary: Python Client Library for Supabase Auth
5
5
  Home-page: https://github.com/supabase/auth-py
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "supabase_auth"
3
- version = "2.7.0" # {x-release-please-version}
3
+ version = "2.8.0" # {x-release-please-version}
4
4
  description = "Python Client Library for Supabase Auth"
5
5
  authors = ["Joel Lee <joel@joellee.org>"]
6
6
  homepage = "https://github.com/supabase/auth-py"
@@ -27,8 +27,8 @@ isort = "^5.12.0"
27
27
  pre-commit = "^3.4.0"
28
28
  pytest-cov = "^5.0.0"
29
29
  pytest-depends = "^1.0.1"
30
- pytest-asyncio = "^0.23.8"
31
- Faker = "^27.0.0"
30
+ pytest-asyncio = "^0.24.0"
31
+ Faker = "^28.1.0"
32
32
  unasync-cli = "^0.0.9"
33
33
 
34
34
  [tool.poetry.group.dev.dependencies]
@@ -13,7 +13,7 @@ from ..types import (
13
13
  AuthMFAAdminListFactorsResponse,
14
14
  GenerateLinkParams,
15
15
  GenerateLinkResponse,
16
- Options,
16
+ InviteUserByEmailOptions,
17
17
  SignOutScope,
18
18
  User,
19
19
  UserResponse,
@@ -57,7 +57,7 @@ class AsyncGoTrueAdminAPI(AsyncGoTrueBaseAPI):
57
57
  async def invite_user_by_email(
58
58
  self,
59
59
  email: str,
60
- options: Options = {},
60
+ options: InviteUserByEmailOptions = {},
61
61
  ) -> UserResponse:
62
62
  """
63
63
  Sends an invite link to an email address.
@@ -61,6 +61,7 @@ from ..types import (
61
61
  OAuthResponse,
62
62
  Options,
63
63
  Provider,
64
+ ResendCredentials,
64
65
  Session,
65
66
  SignInAnonymouslyCredentials,
66
67
  SignInWithIdTokenCredentials,
@@ -519,6 +520,41 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
519
520
  "You must provide either an email or phone number"
520
521
  )
521
522
 
523
+ async def resend(
524
+ self,
525
+ credentials: ResendCredentials,
526
+ ) -> AuthOtpResponse:
527
+ """
528
+ Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
529
+ """
530
+ email = credentials.get("email")
531
+ phone = credentials.get("phone")
532
+ type = credentials.get("type")
533
+ options = credentials.get("options", {})
534
+ email_redirect_to = options.get("email_redirect_to")
535
+ captcha_token = options.get("captcha_token")
536
+ body = {
537
+ "type": type,
538
+ "gotrue_meta_security": {
539
+ "captcha_token": captcha_token,
540
+ },
541
+ }
542
+
543
+ if email is None and phone is None:
544
+ raise AuthInvalidCredentialsError(
545
+ "You must provide either an email or phone number"
546
+ )
547
+
548
+ body.update({"email": email} if email else {"phone": phone})
549
+
550
+ return await self._request(
551
+ "POST",
552
+ "resend",
553
+ body=body,
554
+ redirect_to=email_redirect_to if email else None,
555
+ xform=parse_auth_otp_response,
556
+ )
557
+
522
558
  async def verify_otp(self, params: VerifyOtpParams) -> AuthResponse:
523
559
  """
524
560
  Log in a user given a User supplied OTP received via mobile.
@@ -541,6 +577,18 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
541
577
  self._notify_all_subscribers("SIGNED_IN", response.session)
542
578
  return response
543
579
 
580
+ async def reauthenticate(self) -> AuthResponse:
581
+ session = await self.get_session()
582
+ if not session:
583
+ raise AuthSessionMissingError()
584
+
585
+ return await self._request(
586
+ "GET",
587
+ "reauthenticate",
588
+ jwt=session.access_token,
589
+ xform=parse_auth_response,
590
+ )
591
+
544
592
  async def get_session(self) -> Union[Session, None]:
545
593
  """
546
594
  Returns the session, refreshing it if necessary.
@@ -711,11 +759,7 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
711
759
  self._state_change_emitters[unique_id] = subscription
712
760
  return subscription
713
761
 
714
- async def reset_password_email(
715
- self,
716
- email: str,
717
- options: Options = {},
718
- ) -> None:
762
+ async def reset_password_for_email(self, email: str, options: Options = {}) -> None:
719
763
  """
720
764
  Sends a password reset request to an email address.
721
765
  """
@@ -731,20 +775,41 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
731
775
  redirect_to=options.get("redirect_to"),
732
776
  )
733
777
 
778
+ async def reset_password_email(
779
+ self,
780
+ email: str,
781
+ options: Options = {},
782
+ ) -> None:
783
+ """
784
+ Sends a password reset request to an email address.
785
+ """
786
+ await self.reset_password_for_email(email, options)
787
+
734
788
  # MFA methods
735
789
 
736
790
  async def _enroll(self, params: MFAEnrollParams) -> AuthMFAEnrollResponse:
737
791
  session = await self.get_session()
738
792
  if not session:
739
793
  raise AuthSessionMissingError()
794
+
795
+ body = {
796
+ "friendly_name": params["friendly_name"],
797
+ "factor_type": params["factor_type"],
798
+ }
799
+
800
+ if params["factor_type"] == "phone":
801
+ body["phone"] = params["phone"]
802
+ else:
803
+ body["issuer"] = params["issuer"]
804
+
740
805
  response = await self._request(
741
806
  "POST",
742
807
  "factors",
743
- body=params,
808
+ body=body,
744
809
  jwt=session.access_token,
745
810
  xform=partial(model_validate, AuthMFAEnrollResponse),
746
811
  )
747
- if response.totp.qr_code:
812
+ if params["factor_type"] == "totp" and response.totp.qr_code:
748
813
  response.totp.qr_code = f"data:image/svg+xml;utf-8,{response.totp.qr_code}"
749
814
  return response
750
815
 
@@ -755,6 +820,7 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
755
820
  return await self._request(
756
821
  "POST",
757
822
  f"factors/{params.get('factor_id')}/challenge",
823
+ body={"channel": params["channel"]},
758
824
  jwt=session.access_token,
759
825
  xform=partial(model_validate, AuthMFAChallengeResponse),
760
826
  )
@@ -807,7 +873,8 @@ class AsyncGoTrueClient(AsyncGoTrueBaseAPI):
807
873
  response = await self.get_user()
808
874
  all = response.user.factors or []
809
875
  totp = [f for f in all if f.factor_type == "totp" and f.status == "verified"]
810
- return AuthMFAListFactorsResponse(all=all, totp=totp)
876
+ phone = [f for f in all if f.factor_type == "phone" and f.status == "verified"]
877
+ return AuthMFAListFactorsResponse(all=all, totp=totp, phone=phone)
811
878
 
812
879
  async def _get_authenticator_assurance_level(
813
880
  self,
@@ -13,7 +13,7 @@ from ..types import (
13
13
  AuthMFAAdminListFactorsResponse,
14
14
  GenerateLinkParams,
15
15
  GenerateLinkResponse,
16
- Options,
16
+ InviteUserByEmailOptions,
17
17
  SignOutScope,
18
18
  User,
19
19
  UserResponse,
@@ -57,7 +57,7 @@ class SyncGoTrueAdminAPI(SyncGoTrueBaseAPI):
57
57
  def invite_user_by_email(
58
58
  self,
59
59
  email: str,
60
- options: Options = {},
60
+ options: InviteUserByEmailOptions = {},
61
61
  ) -> UserResponse:
62
62
  """
63
63
  Sends an invite link to an email address.
@@ -61,6 +61,7 @@ from ..types import (
61
61
  OAuthResponse,
62
62
  Options,
63
63
  Provider,
64
+ ResendCredentials,
64
65
  Session,
65
66
  SignInAnonymouslyCredentials,
66
67
  SignInWithIdTokenCredentials,
@@ -513,6 +514,41 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
513
514
  "You must provide either an email or phone number"
514
515
  )
515
516
 
517
+ def resend(
518
+ self,
519
+ credentials: ResendCredentials,
520
+ ) -> AuthOtpResponse:
521
+ """
522
+ Resends an existing signup confirmation email, email change email, SMS OTP or phone change OTP.
523
+ """
524
+ email = credentials.get("email")
525
+ phone = credentials.get("phone")
526
+ type = credentials.get("type")
527
+ options = credentials.get("options", {})
528
+ email_redirect_to = options.get("email_redirect_to")
529
+ captcha_token = options.get("captcha_token")
530
+ body = {
531
+ "type": type,
532
+ "gotrue_meta_security": {
533
+ "captcha_token": captcha_token,
534
+ },
535
+ }
536
+
537
+ if email is None and phone is None:
538
+ raise AuthInvalidCredentialsError(
539
+ "You must provide either an email or phone number"
540
+ )
541
+
542
+ body.update({"email": email} if email else {"phone": phone})
543
+
544
+ return self._request(
545
+ "POST",
546
+ "resend",
547
+ body=body,
548
+ redirect_to=email_redirect_to if email else None,
549
+ xform=parse_auth_otp_response,
550
+ )
551
+
516
552
  def verify_otp(self, params: VerifyOtpParams) -> AuthResponse:
517
553
  """
518
554
  Log in a user given a User supplied OTP received via mobile.
@@ -535,6 +571,18 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
535
571
  self._notify_all_subscribers("SIGNED_IN", response.session)
536
572
  return response
537
573
 
574
+ def reauthenticate(self) -> AuthResponse:
575
+ session = self.get_session()
576
+ if not session:
577
+ raise AuthSessionMissingError()
578
+
579
+ return self._request(
580
+ "GET",
581
+ "reauthenticate",
582
+ jwt=session.access_token,
583
+ xform=parse_auth_response,
584
+ )
585
+
538
586
  def get_session(self) -> Union[Session, None]:
539
587
  """
540
588
  Returns the session, refreshing it if necessary.
@@ -703,11 +751,7 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
703
751
  self._state_change_emitters[unique_id] = subscription
704
752
  return subscription
705
753
 
706
- def reset_password_email(
707
- self,
708
- email: str,
709
- options: Options = {},
710
- ) -> None:
754
+ def reset_password_for_email(self, email: str, options: Options = {}) -> None:
711
755
  """
712
756
  Sends a password reset request to an email address.
713
757
  """
@@ -723,20 +767,41 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
723
767
  redirect_to=options.get("redirect_to"),
724
768
  )
725
769
 
770
+ def reset_password_email(
771
+ self,
772
+ email: str,
773
+ options: Options = {},
774
+ ) -> None:
775
+ """
776
+ Sends a password reset request to an email address.
777
+ """
778
+ self.reset_password_for_email(email, options)
779
+
726
780
  # MFA methods
727
781
 
728
782
  def _enroll(self, params: MFAEnrollParams) -> AuthMFAEnrollResponse:
729
783
  session = self.get_session()
730
784
  if not session:
731
785
  raise AuthSessionMissingError()
786
+
787
+ body = {
788
+ "friendly_name": params["friendly_name"],
789
+ "factor_type": params["factor_type"],
790
+ }
791
+
792
+ if params["factor_type"] == "phone":
793
+ body["phone"] = params["phone"]
794
+ else:
795
+ body["issuer"] = params["issuer"]
796
+
732
797
  response = self._request(
733
798
  "POST",
734
799
  "factors",
735
- body=params,
800
+ body=body,
736
801
  jwt=session.access_token,
737
802
  xform=partial(model_validate, AuthMFAEnrollResponse),
738
803
  )
739
- if response.totp.qr_code:
804
+ if params["factor_type"] == "totp" and response.totp.qr_code:
740
805
  response.totp.qr_code = f"data:image/svg+xml;utf-8,{response.totp.qr_code}"
741
806
  return response
742
807
 
@@ -747,6 +812,7 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
747
812
  return self._request(
748
813
  "POST",
749
814
  f"factors/{params.get('factor_id')}/challenge",
815
+ body={"channel": params["channel"]},
750
816
  jwt=session.access_token,
751
817
  xform=partial(model_validate, AuthMFAChallengeResponse),
752
818
  )
@@ -799,7 +865,8 @@ class SyncGoTrueClient(SyncGoTrueBaseAPI):
799
865
  response = self.get_user()
800
866
  all = response.user.factors or []
801
867
  totp = [f for f in all if f.factor_type == "totp" and f.status == "verified"]
802
- return AuthMFAListFactorsResponse(all=all, totp=totp)
868
+ phone = [f for f in all if f.factor_type == "phone" and f.status == "verified"]
869
+ return AuthMFAListFactorsResponse(all=all, totp=totp, phone=phone)
803
870
 
804
871
  def _get_authenticator_assurance_level(
805
872
  self,
@@ -4,7 +4,7 @@ from datetime import datetime
4
4
  from time import time
5
5
  from typing import Any, Callable, Dict, List, Union
6
6
 
7
- from pydantic import BaseModel
7
+ from pydantic import BaseModel, ConfigDict
8
8
 
9
9
  try:
10
10
  # > 2
@@ -83,6 +83,11 @@ class AMREntry(BaseModel):
83
83
 
84
84
 
85
85
  class Options(TypedDict):
86
+ redirect_to: NotRequired[str]
87
+ captcha_token: NotRequired[str]
88
+
89
+
90
+ class InviteUserByEmailOptions(TypedDict):
86
91
  redirect_to: NotRequired[str]
87
92
  data: NotRequired[Any]
88
93
 
@@ -180,7 +185,7 @@ class Factor(BaseModel):
180
185
  """
181
186
  Friendly name of the factor, useful to disambiguate between multiple factors.
182
187
  """
183
- factor_type: Union[Literal["totp"], str]
188
+ factor_type: Union[Literal["totp", "phone"], str]
184
189
  """
185
190
  Type of factor. Only `totp` supported with this version but may change in
186
191
  future versions.
@@ -376,6 +381,30 @@ SignInWithPasswordlessCredentials = Union[
376
381
  ]
377
382
 
378
383
 
384
+ class ResendEmailCredentialsOptions(TypedDict):
385
+ email_redirect_to: NotRequired[str]
386
+ captcha_token: NotRequired[str]
387
+
388
+
389
+ class ResendEmailCredentials(TypedDict):
390
+ type: Literal["signup", "email_change"]
391
+ email: str
392
+ options: NotRequired[ResendEmailCredentialsOptions]
393
+
394
+
395
+ class ResendPhoneCredentialsOptions(TypedDict):
396
+ captcha_token: NotRequired[str]
397
+
398
+
399
+ class ResendPhoneCredentials(TypedDict):
400
+ type: Literal["sms", "phone_change"]
401
+ phone: str
402
+ options: NotRequired[ResendPhoneCredentialsOptions]
403
+
404
+
405
+ ResendCredentials = Union[ResendEmailCredentials, ResendPhoneCredentials]
406
+
407
+
379
408
  class SignInWithOAuthCredentialsOptions(TypedDict):
380
409
  redirect_to: NotRequired[str]
381
410
  scopes: NotRequired[str]
@@ -492,9 +521,10 @@ GenerateLinkType = Literal[
492
521
 
493
522
 
494
523
  class MFAEnrollParams(TypedDict):
495
- factor_type: Literal["totp"]
524
+ factor_type: Literal["totp", "phone"]
496
525
  issuer: NotRequired[str]
497
526
  friendly_name: NotRequired[str]
527
+ phone: str
498
528
 
499
529
 
500
530
  class MFAUnenrollParams(TypedDict):
@@ -539,6 +569,7 @@ class MFAChallengeParams(TypedDict):
539
569
  """
540
570
  ID of the factor to be challenged.
541
571
  """
572
+ channel: NotRequired[Literal["sms", "whatsapp"]]
542
573
 
543
574
 
544
575
  class MFAChallengeAndVerifyParams(TypedDict):
@@ -600,7 +631,7 @@ class AuthMFAEnrollResponse(BaseModel):
600
631
  """
601
632
  ID of the factor that was just enrolled (in an unverified state).
602
633
  """
603
- type: Literal["totp"]
634
+ type: Literal["totp", "phone"]
604
635
  """
605
636
  Type of MFA factor. Only `totp` supported for now.
606
637
  """
@@ -608,6 +639,15 @@ class AuthMFAEnrollResponse(BaseModel):
608
639
  """
609
640
  TOTP enrollment information.
610
641
  """
642
+ model_config = ConfigDict(arbitrary_types_allowed=True)
643
+ friendly_name: str
644
+ """
645
+ Friendly name of the factor, useful for distinguishing between factors
646
+ """
647
+ phone: str
648
+ """
649
+ Phone number of the MFA factor in E.164 format. Used to send messages
650
+ """
611
651
 
612
652
 
613
653
  class AuthMFAUnenrollResponse(BaseModel):
@@ -626,6 +666,10 @@ class AuthMFAChallengeResponse(BaseModel):
626
666
  """
627
667
  Timestamp in UNIX seconds when this challenge will no longer be usable.
628
668
  """
669
+ factor_type: Literal["totp", "phone"]
670
+ """
671
+ Factor Type which generated the challenge
672
+ """
629
673
 
630
674
 
631
675
  class AuthMFAListFactorsResponse(BaseModel):
@@ -637,6 +681,10 @@ class AuthMFAListFactorsResponse(BaseModel):
637
681
  """
638
682
  Only verified TOTP factors. (A subset of `all`.)
639
683
  """
684
+ phone: List[Factor]
685
+ """
686
+ Only verified Phone factors. (A subset of `all`.)
687
+ """
640
688
 
641
689
 
642
690
  AuthenticatorAssuranceLevels = Literal["aal1", "aal2"]
@@ -0,0 +1 @@
1
+ __version__ = "2.8.0" # {x-release-please-version}
@@ -1 +0,0 @@
1
- __version__ = "2.7.0" # {x-release-please-version}
File without changes