corebase 1.0.0__py3-none-any.whl

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 (106) hide show
  1. corebase/__init__.py +108 -0
  2. corebase/_async/__init__.py +1 -0
  3. corebase/_async/auth_client.py +55 -0
  4. corebase/_async/client.py +398 -0
  5. corebase/_sync/__init__.py +1 -0
  6. corebase/_sync/auth_client.py +55 -0
  7. corebase/_sync/client.py +393 -0
  8. corebase/auth/__init__.py +20 -0
  9. corebase/auth/_async/__init__.py +1 -0
  10. corebase/auth/_async/gotrue_admin_api.py +356 -0
  11. corebase/auth/_async/gotrue_admin_mfa_api.py +32 -0
  12. corebase/auth/_async/gotrue_admin_oauth_api.py +93 -0
  13. corebase/auth/_async/gotrue_base_api.py +78 -0
  14. corebase/auth/_async/gotrue_client.py +1404 -0
  15. corebase/auth/_async/gotrue_mfa_api.py +94 -0
  16. corebase/auth/_async/storage.py +31 -0
  17. corebase/auth/_sync/__init__.py +1 -0
  18. corebase/auth/_sync/gotrue_admin_api.py +356 -0
  19. corebase/auth/_sync/gotrue_admin_mfa_api.py +32 -0
  20. corebase/auth/_sync/gotrue_admin_oauth_api.py +93 -0
  21. corebase/auth/_sync/gotrue_base_api.py +78 -0
  22. corebase/auth/_sync/gotrue_client.py +1394 -0
  23. corebase/auth/_sync/gotrue_mfa_api.py +94 -0
  24. corebase/auth/_sync/storage.py +31 -0
  25. corebase/auth/constants.py +15 -0
  26. corebase/auth/errors.py +259 -0
  27. corebase/auth/helpers.py +288 -0
  28. corebase/auth/py.typed +0 -0
  29. corebase/auth/timer.py +53 -0
  30. corebase/auth/types.py +1021 -0
  31. corebase/auth/version.py +1 -0
  32. corebase/client.py +12 -0
  33. corebase/functions/__init__.py +47 -0
  34. corebase/functions/_async/__init__.py +1 -0
  35. corebase/functions/_async/functions_client.py +218 -0
  36. corebase/functions/_sync/__init__.py +1 -0
  37. corebase/functions/_sync/functions_client.py +218 -0
  38. corebase/functions/errors.py +62 -0
  39. corebase/functions/py.typed +0 -0
  40. corebase/functions/utils.py +33 -0
  41. corebase/functions/version.py +1 -0
  42. corebase/lib/__init__.py +3 -0
  43. corebase/lib/client_options.py +189 -0
  44. corebase/migrate/__init__.py +374 -0
  45. corebase/migrate/__main__.py +7 -0
  46. corebase/postgrest/__init__.py +62 -0
  47. corebase/postgrest/_async/__init__.py +1 -0
  48. corebase/postgrest/_async/client.py +206 -0
  49. corebase/postgrest/_async/request_builder.py +503 -0
  50. corebase/postgrest/_sync/__init__.py +1 -0
  51. corebase/postgrest/_sync/client.py +206 -0
  52. corebase/postgrest/_sync/request_builder.py +503 -0
  53. corebase/postgrest/base_client.py +61 -0
  54. corebase/postgrest/base_request_builder.py +787 -0
  55. corebase/postgrest/constants.py +6 -0
  56. corebase/postgrest/exceptions.py +115 -0
  57. corebase/postgrest/py.typed +0 -0
  58. corebase/postgrest/types.py +72 -0
  59. corebase/postgrest/utils.py +91 -0
  60. corebase/postgrest/version.py +1 -0
  61. corebase/py.typed +0 -0
  62. corebase/realtime/__init__.py +17 -0
  63. corebase/realtime/_async/__init__.py +0 -0
  64. corebase/realtime/_async/channel.py +766 -0
  65. corebase/realtime/_async/client.py +498 -0
  66. corebase/realtime/_async/presence.py +185 -0
  67. corebase/realtime/_async/push.py +162 -0
  68. corebase/realtime/_async/timer.py +41 -0
  69. corebase/realtime/_sync/__init__.py +0 -0
  70. corebase/realtime/_sync/channel.py +30 -0
  71. corebase/realtime/_sync/client.py +71 -0
  72. corebase/realtime/_sync/presence.py +10 -0
  73. corebase/realtime/exceptions.py +38 -0
  74. corebase/realtime/message.py +176 -0
  75. corebase/realtime/py.typed +0 -0
  76. corebase/realtime/transformers.py +9 -0
  77. corebase/realtime/types.py +246 -0
  78. corebase/realtime/utils.py +5 -0
  79. corebase/realtime/version.py +1 -0
  80. corebase/storage/__init__.py +56 -0
  81. corebase/storage/_async/__init__.py +1 -0
  82. corebase/storage/_async/analytics.py +82 -0
  83. corebase/storage/_async/bucket.py +142 -0
  84. corebase/storage/_async/client.py +106 -0
  85. corebase/storage/_async/file_api.py +630 -0
  86. corebase/storage/_async/request.py +32 -0
  87. corebase/storage/_async/vectors.py +213 -0
  88. corebase/storage/_sync/__init__.py +1 -0
  89. corebase/storage/_sync/analytics.py +80 -0
  90. corebase/storage/_sync/bucket.py +142 -0
  91. corebase/storage/_sync/client.py +106 -0
  92. corebase/storage/_sync/file_api.py +630 -0
  93. corebase/storage/_sync/request.py +32 -0
  94. corebase/storage/_sync/vectors.py +199 -0
  95. corebase/storage/constants.py +16 -0
  96. corebase/storage/exceptions.py +84 -0
  97. corebase/storage/py.typed +0 -0
  98. corebase/storage/types.py +313 -0
  99. corebase/storage/utils.py +26 -0
  100. corebase/storage/version.py +1 -0
  101. corebase/types.py +8 -0
  102. corebase/version.py +1 -0
  103. corebase-1.0.0.dist-info/METADATA +78 -0
  104. corebase-1.0.0.dist-info/RECORD +106 -0
  105. corebase-1.0.0.dist-info/WHEEL +4 -0
  106. corebase-1.0.0.dist-info/licenses/LICENSE +21 -0
corebase/auth/types.py ADDED
@@ -0,0 +1,1021 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Callable
4
+ from datetime import datetime
5
+ from time import time
6
+ from typing import Any, Literal, NotRequired
7
+
8
+ from pydantic import (
9
+ BaseModel,
10
+ ConfigDict,
11
+ Field,
12
+ TypeAdapter,
13
+ model_validator,
14
+ with_config,
15
+ )
16
+ from typing_extensions import TypedDict
17
+
18
+ Provider = Literal[
19
+ "apple",
20
+ "azure",
21
+ "bitbucket",
22
+ "discord",
23
+ "facebook",
24
+ "figma",
25
+ "fly",
26
+ "github",
27
+ "gitlab",
28
+ "google",
29
+ "kakao",
30
+ "keycloak",
31
+ "linkedin",
32
+ "linkedin_oidc",
33
+ "notion",
34
+ "slack",
35
+ "slack_oidc",
36
+ "spotify",
37
+ "twitch",
38
+ "twitter", # Uses OAuth 1.0a
39
+ "x", # Uses OAuth 2.0
40
+ "workos",
41
+ "zoom",
42
+ ]
43
+
44
+ EmailOtpType = Literal[
45
+ "signup", "invite", "magiclink", "recovery", "email_change", "email"
46
+ ]
47
+
48
+ AuthChangeEventMFA = Literal["MFA_CHALLENGE_VERIFIED"]
49
+
50
+ AuthFlowType = Literal["pkce", "implicit"]
51
+
52
+ AuthChangeEvent = Literal[
53
+ "PASSWORD_RECOVERY",
54
+ "SIGNED_IN",
55
+ "SIGNED_OUT",
56
+ "TOKEN_REFRESHED",
57
+ "USER_UPDATED",
58
+ "USER_DELETED",
59
+ AuthChangeEventMFA,
60
+ ]
61
+
62
+
63
+ class AMREntry(BaseModel):
64
+ """
65
+ An authentication methord reference (AMR) entry.
66
+
67
+ An entry designates what method was used by the user to verify their
68
+ identity and at what time.
69
+ """
70
+
71
+ method: Literal["password", "otp", "oauth", "mfa/totp"] | str
72
+ """
73
+ Authentication method name.
74
+ """
75
+ timestamp: int
76
+ """
77
+ Timestamp when the method was successfully used. Represents number of
78
+ seconds since 1st January 1970 (UNIX epoch) in UTC.
79
+ """
80
+
81
+
82
+ class AMREntryDict(TypedDict):
83
+ timestamp: int
84
+ method: Literal["password", "otp", "oauth", "mfa/totp"] | str
85
+
86
+
87
+ class Options(TypedDict):
88
+ redirect_to: NotRequired[str]
89
+ captcha_token: NotRequired[str]
90
+
91
+
92
+ class UpdateUserOptions(TypedDict):
93
+ email_redirect_to: NotRequired[str]
94
+
95
+
96
+ class InviteUserByEmailOptions(TypedDict):
97
+ redirect_to: NotRequired[str]
98
+ data: NotRequired[Any]
99
+
100
+
101
+ class AuthResponse(BaseModel):
102
+ user: User | None = None
103
+ session: Session | None = None
104
+
105
+
106
+ class AuthOtpResponse(BaseModel):
107
+ user: None = None
108
+ session: None = None
109
+ message_id: str | None = None
110
+
111
+
112
+ class OAuthResponse(BaseModel):
113
+ provider: Provider
114
+ url: str
115
+
116
+
117
+ class SSOResponse(BaseModel):
118
+ url: str
119
+
120
+
121
+ class LinkIdentityResponse(BaseModel):
122
+ url: str
123
+
124
+
125
+ class IdentitiesResponse(BaseModel):
126
+ identities: list[UserIdentity]
127
+
128
+
129
+ class UserList(BaseModel):
130
+ users: list[User]
131
+
132
+
133
+ class UserResponse(BaseModel):
134
+ user: User
135
+
136
+
137
+ class Session(BaseModel):
138
+ provider_token: str | None = None
139
+ """
140
+ The oauth provider token. If present, this can be used to make external API
141
+ requests to the oauth provider used.
142
+ """
143
+ provider_refresh_token: str | None = None
144
+ """
145
+ The oauth provider refresh token. If present, this can be used to refresh
146
+ the provider_token via the oauth provider's API.
147
+
148
+ Not all oauth providers return a provider refresh token. If the
149
+ provider_refresh_token is missing, please refer to the oauth provider's
150
+ documentation for information on how to obtain the provider refresh token.
151
+ """
152
+ access_token: str
153
+ refresh_token: str
154
+ expires_in: int
155
+ """
156
+ The number of seconds until the token expires (since it was issued).
157
+ Returned when a login is confirmed.
158
+ """
159
+ expires_at: int | None = None
160
+ """
161
+ A timestamp of when the token will expire. Returned when a login is confirmed.
162
+ """
163
+ token_type: str
164
+ user: User
165
+
166
+ @model_validator(mode="after")
167
+ def validator(self) -> Session:
168
+ if self.expires_in and not self.expires_at:
169
+ self.expires_at = round(time()) + self.expires_in
170
+ return self
171
+
172
+
173
+ class UserIdentity(BaseModel):
174
+ id: str
175
+ identity_id: str
176
+ user_id: str
177
+ identity_data: dict[str, Any]
178
+ provider: str
179
+ created_at: datetime
180
+ last_sign_in_at: datetime | None = None
181
+ updated_at: datetime | None = None
182
+
183
+
184
+ class Factor(BaseModel):
185
+ """
186
+ A MFA factor.
187
+ """
188
+
189
+ id: str
190
+ """
191
+ ID of the factor.
192
+ """
193
+ friendly_name: str | None = None
194
+ """
195
+ Friendly name of the factor, useful to disambiguate between multiple factors.
196
+ """
197
+ phone: str | None = None
198
+ """
199
+ Phone number associated with a phone factor.
200
+ """
201
+ factor_type: Literal["totp", "phone"] | str
202
+ """
203
+ Type of factor. Only `totp` supported with this version but may change in
204
+ future versions.
205
+ """
206
+ status: Literal["verified", "unverified"]
207
+ """
208
+ Factor's status.
209
+ """
210
+ created_at: datetime
211
+ updated_at: datetime
212
+
213
+
214
+ class User(BaseModel):
215
+ id: str
216
+ app_metadata: dict[str, Any]
217
+ user_metadata: dict[str, Any]
218
+ aud: str
219
+ confirmation_sent_at: datetime | None = None
220
+ recovery_sent_at: datetime | None = None
221
+ email_change_sent_at: datetime | None = None
222
+ new_email: str | None = None
223
+ new_phone: str | None = None
224
+ invited_at: datetime | None = None
225
+ action_link: str | None = None
226
+ email: str | None = None
227
+ phone: str | None = None
228
+ created_at: datetime
229
+ confirmed_at: datetime | None = None
230
+ email_confirmed_at: datetime | None = None
231
+ phone_confirmed_at: datetime | None = None
232
+ last_sign_in_at: datetime | None = None
233
+ role: str | None = None
234
+ updated_at: datetime | None = None
235
+ identities: list[UserIdentity] | None = None
236
+ is_anonymous: bool = False
237
+ is_sso_user: bool = False
238
+ factors: list[Factor] | None = None
239
+ deleted_at: str | None = None
240
+ banned_until: str | None = None
241
+
242
+
243
+ class UserAttributes(TypedDict):
244
+ email: NotRequired[str]
245
+ phone: NotRequired[str]
246
+ password: NotRequired[str]
247
+ data: NotRequired[Any]
248
+ nonce: NotRequired[str]
249
+ current_password: NotRequired[str]
250
+
251
+
252
+ class AdminUserAttributes(UserAttributes, TypedDict):
253
+ user_metadata: NotRequired[Any]
254
+ app_metadata: NotRequired[Any]
255
+ email_confirm: NotRequired[bool]
256
+ phone_confirm: NotRequired[bool]
257
+ ban_duration: NotRequired[str | Literal["none"]]
258
+ role: NotRequired[str]
259
+ """
260
+ The `role` claim set in the user's access token JWT.
261
+
262
+ When a user signs up, this role is set to `authenticated` by default. You should only modify the `role` if you need to provision several levels of admin access that have different permissions on individual columns in your database.
263
+
264
+ Setting this role to `service_role` is not recommended as it grants the user admin privileges.
265
+ """
266
+ password_hash: NotRequired[str]
267
+ """
268
+ The `password_hash` for the user's password.
269
+
270
+ Allows you to specify a password hash for the user. This is useful for migrating a user's password hash from another service.
271
+
272
+ Supports bcrypt and argon2 password hashes.
273
+ """
274
+ id: NotRequired[str]
275
+ """
276
+ The `id` for the user.
277
+
278
+ Allows you to overwrite the default `id` set for the user.
279
+ """
280
+
281
+
282
+ class Subscription(BaseModel):
283
+ id: str
284
+ """
285
+ The subscriber UUID. This will be set by the client.
286
+ """
287
+ callback: Callable[[AuthChangeEvent, Session | None], None]
288
+ """
289
+ The function to call every time there is an event.
290
+ """
291
+ unsubscribe: Callable[[], None]
292
+ """
293
+ Call this to remove the listener.
294
+ """
295
+
296
+
297
+ class UpdatableFactorAttributes(TypedDict):
298
+ friendly_name: str
299
+
300
+
301
+ class SignUpWithEmailAndPasswordCredentialsOptions(
302
+ TypedDict,
303
+ ):
304
+ email_redirect_to: NotRequired[str]
305
+ data: NotRequired[Any]
306
+ captcha_token: NotRequired[str]
307
+
308
+
309
+ class SignUpWithEmailAndPasswordCredentials(TypedDict):
310
+ email: str
311
+ password: str
312
+ options: NotRequired[SignUpWithEmailAndPasswordCredentialsOptions]
313
+
314
+
315
+ class SignUpWithPhoneAndPasswordCredentialsOptions(TypedDict):
316
+ data: NotRequired[Any]
317
+ captcha_token: NotRequired[str]
318
+ channel: NotRequired[Literal["sms", "whatsapp"]]
319
+
320
+
321
+ class SignUpWithPhoneAndPasswordCredentials(TypedDict):
322
+ phone: str
323
+ password: str
324
+ options: NotRequired[SignUpWithPhoneAndPasswordCredentialsOptions]
325
+
326
+
327
+ SignUpWithPasswordCredentials = (
328
+ SignUpWithEmailAndPasswordCredentials | SignUpWithPhoneAndPasswordCredentials
329
+ )
330
+
331
+
332
+ class SignInWithPasswordCredentialsOptions(TypedDict):
333
+ data: NotRequired[Any]
334
+ captcha_token: NotRequired[str]
335
+
336
+
337
+ class SignInWithEmailAndPasswordCredentials(TypedDict):
338
+ email: str
339
+ password: str
340
+ options: NotRequired[SignInWithPasswordCredentialsOptions]
341
+
342
+
343
+ class SignInWithPhoneAndPasswordCredentials(TypedDict):
344
+ phone: str
345
+ password: str
346
+ options: NotRequired[SignInWithPasswordCredentialsOptions]
347
+
348
+
349
+ SignInWithPasswordCredentials = (
350
+ SignInWithEmailAndPasswordCredentials | SignInWithPhoneAndPasswordCredentials
351
+ )
352
+
353
+
354
+ class SignInWithIdTokenCredentials(TypedDict):
355
+ """
356
+ Provider name or OIDC `iss` value identifying which provider should be used to verify the provided token. Supported names: `google`, `apple`, `azure`, `facebook`, `kakao`, `keycloak` (deprecated).
357
+ """
358
+
359
+ provider: Literal["google", "apple", "azure", "facebook", "kakao"]
360
+ token: str
361
+ access_token: NotRequired[str]
362
+ nonce: NotRequired[str]
363
+ options: NotRequired[SignInWithIdTokenCredentialsOptions]
364
+
365
+
366
+ class SignInWithIdTokenCredentialsOptions(TypedDict):
367
+ captcha_token: NotRequired[str]
368
+
369
+
370
+ class SignInWithEmailAndPasswordlessCredentialsOptions(TypedDict):
371
+ email_redirect_to: NotRequired[str]
372
+ should_create_user: NotRequired[bool]
373
+ data: NotRequired[Any]
374
+ captcha_token: NotRequired[str]
375
+
376
+
377
+ class SignInWithEmailAndPasswordlessCredentials(TypedDict):
378
+ email: str
379
+ options: NotRequired[SignInWithEmailAndPasswordlessCredentialsOptions]
380
+
381
+
382
+ class SignInWithPhoneAndPasswordlessCredentialsOptions(TypedDict):
383
+ should_create_user: NotRequired[bool]
384
+ data: NotRequired[Any]
385
+ captcha_token: NotRequired[str]
386
+ channel: NotRequired[Literal["sms", "whatsapp"]]
387
+
388
+
389
+ class SignInWithPhoneAndPasswordlessCredentials(TypedDict):
390
+ phone: str
391
+ options: NotRequired[SignInWithPhoneAndPasswordlessCredentialsOptions]
392
+
393
+
394
+ SignInWithPasswordlessCredentials = (
395
+ SignInWithEmailAndPasswordlessCredentials
396
+ | SignInWithPhoneAndPasswordlessCredentials
397
+ )
398
+
399
+
400
+ class ResendEmailCredentialsOptions(TypedDict):
401
+ email_redirect_to: NotRequired[str]
402
+ captcha_token: NotRequired[str]
403
+
404
+
405
+ class ResendEmailCredentials(TypedDict):
406
+ type: Literal["signup", "email_change"]
407
+ email: str
408
+ options: NotRequired[ResendEmailCredentialsOptions]
409
+
410
+
411
+ class ResendPhoneCredentialsOptions(TypedDict):
412
+ captcha_token: NotRequired[str]
413
+
414
+
415
+ class ResendPhoneCredentials(TypedDict):
416
+ type: Literal["sms", "phone_change"]
417
+ phone: str
418
+ options: NotRequired[ResendPhoneCredentialsOptions]
419
+
420
+
421
+ ResendCredentials = ResendEmailCredentials | ResendPhoneCredentials
422
+
423
+
424
+ class SignInWithOAuthCredentialsOptions(TypedDict):
425
+ redirect_to: NotRequired[str]
426
+ scopes: NotRequired[str]
427
+ query_params: NotRequired[dict[str, str]]
428
+
429
+
430
+ class SignInWithOAuthCredentials(TypedDict):
431
+ provider: Provider
432
+ options: NotRequired[SignInWithOAuthCredentialsOptions]
433
+
434
+
435
+ class SignInWithSSOCredentials(TypedDict):
436
+ provider_id: NotRequired[str]
437
+ domain: NotRequired[str]
438
+ options: NotRequired[SignInWithSSOOptions]
439
+
440
+
441
+ class SignInWithSSOOptions(TypedDict):
442
+ redirect_to: NotRequired[str]
443
+ skip_http_redirect: NotRequired[bool]
444
+
445
+
446
+ class SignInAnonymouslyCredentials(TypedDict):
447
+ options: NotRequired[SignInAnonymouslyCredentialsOptions]
448
+
449
+
450
+ class SignInAnonymouslyCredentialsOptions(TypedDict):
451
+ data: NotRequired[Any]
452
+ captcha_token: NotRequired[str]
453
+
454
+
455
+ class VerifyOtpParamsOptions(TypedDict):
456
+ redirect_to: NotRequired[str]
457
+ captcha_token: NotRequired[str]
458
+
459
+
460
+ class VerifyEmailOtpParams(TypedDict):
461
+ email: str
462
+ token: str
463
+ type: EmailOtpType
464
+ options: NotRequired[VerifyOtpParamsOptions]
465
+
466
+
467
+ class VerifyMobileOtpParams(TypedDict):
468
+ phone: str
469
+ token: str
470
+ type: Literal[
471
+ "sms",
472
+ "phone_change",
473
+ ]
474
+ options: NotRequired[VerifyOtpParamsOptions]
475
+
476
+
477
+ class VerifyTokenHashParams(TypedDict):
478
+ token_hash: str
479
+ type: EmailOtpType
480
+ options: NotRequired[VerifyOtpParamsOptions]
481
+
482
+
483
+ VerifyOtpParams = VerifyEmailOtpParams | VerifyMobileOtpParams | VerifyTokenHashParams
484
+
485
+
486
+ class GenerateLinkParamsOptions(TypedDict):
487
+ redirect_to: NotRequired[str]
488
+
489
+
490
+ class GenerateLinkParamsWithDataOptions(GenerateLinkParamsOptions, TypedDict):
491
+ data: NotRequired[Any]
492
+
493
+
494
+ class GenerateSignupLinkParams(TypedDict):
495
+ type: Literal["signup"]
496
+ email: str
497
+ password: str
498
+ options: NotRequired[GenerateLinkParamsWithDataOptions]
499
+
500
+
501
+ class GenerateInviteOrMagiclinkParams(TypedDict):
502
+ type: Literal["invite", "magiclink"]
503
+ email: str
504
+ options: NotRequired[GenerateLinkParamsWithDataOptions]
505
+
506
+
507
+ class GenerateRecoveryLinkParams(TypedDict):
508
+ type: Literal["recovery"]
509
+ email: str
510
+ options: NotRequired[GenerateLinkParamsOptions]
511
+
512
+
513
+ class GenerateEmailChangeLinkParams(TypedDict):
514
+ type: Literal["email_change_current", "email_change_new"]
515
+ email: str
516
+ new_email: str
517
+ options: NotRequired[GenerateLinkParamsOptions]
518
+
519
+
520
+ GenerateLinkParams = (
521
+ GenerateSignupLinkParams
522
+ | GenerateInviteOrMagiclinkParams
523
+ | GenerateRecoveryLinkParams
524
+ | GenerateEmailChangeLinkParams
525
+ )
526
+
527
+ GenerateLinkType = Literal[
528
+ "signup",
529
+ "invite",
530
+ "magiclink",
531
+ "recovery",
532
+ "email_change_current",
533
+ "email_change_new",
534
+ ]
535
+
536
+
537
+ class MFAEnrollTOTPParams(TypedDict):
538
+ factor_type: Literal["totp"]
539
+ issuer: NotRequired[str]
540
+ friendly_name: NotRequired[str]
541
+
542
+
543
+ class MFAEnrollPhoneParams(TypedDict):
544
+ factor_type: Literal["phone"]
545
+ friendly_name: NotRequired[str]
546
+ phone: str
547
+
548
+
549
+ MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams
550
+
551
+
552
+ class MFAUnenrollParams(TypedDict):
553
+ factor_id: str
554
+ """
555
+ ID of the factor being unenrolled.
556
+ """
557
+
558
+
559
+ class CodeExchangeParams(TypedDict):
560
+ code_verifier: NotRequired[str]
561
+ """
562
+ Randomly generated string. Defaults to the verifier stored by the PKCE flow.
563
+ """
564
+ auth_code: str
565
+ """
566
+ Code returned after completing one of the authorization flows
567
+ """
568
+ redirect_to: NotRequired[str]
569
+ """
570
+ The URL to route to after a session is successfully obtained
571
+ """
572
+
573
+
574
+ class MFAVerifyParams(TypedDict):
575
+ factor_id: str
576
+ """
577
+ ID of the factor being verified.
578
+ """
579
+ challenge_id: str
580
+ """
581
+ ID of the challenge being verified.
582
+ """
583
+ code: str
584
+ """
585
+ Verification code provided by the user.
586
+ """
587
+
588
+
589
+ class MFAChallengeParams(TypedDict):
590
+ factor_id: str
591
+ """
592
+ ID of the factor to be challenged.
593
+ """
594
+ channel: NotRequired[Literal["sms", "whatsapp"]]
595
+
596
+
597
+ class MFAChallengeAndVerifyParams(TypedDict):
598
+ factor_id: str
599
+ """
600
+ ID of the factor being verified.
601
+ """
602
+ code: str
603
+ """
604
+ Verification code provided by the user.
605
+ """
606
+
607
+
608
+ class AuthMFAVerifyResponse(BaseModel):
609
+ access_token: str
610
+ """
611
+ New access token (JWT) after successful verification.
612
+ """
613
+ token_type: str
614
+ """
615
+ Type of token, typically `Bearer`.
616
+ """
617
+ expires_in: int
618
+ """
619
+ Number of seconds in which the access token will expire.
620
+ """
621
+ refresh_token: str
622
+ """
623
+ Refresh token you can use to obtain new access tokens when expired.
624
+ """
625
+ user: User
626
+ """
627
+ Updated user profile.
628
+ """
629
+
630
+
631
+ class AuthMFAEnrollResponseTotp(BaseModel):
632
+ qr_code: str
633
+ """
634
+ Contains a QR code encoding the authenticator URI. You can
635
+ convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
636
+ the value. Avoid logging this value to the console.
637
+ """
638
+ secret: str
639
+ """
640
+ The TOTP secret (also encoded in the QR code). Show this secret
641
+ in a password-style field to the user, in case they are unable to
642
+ scan the QR code. Avoid logging this value to the console.
643
+ """
644
+ uri: str
645
+ """
646
+ The authenticator URI encoded within the QR code, should you need
647
+ to use it. Avoid loggin this value to the console.
648
+ """
649
+
650
+
651
+ class AuthMFAEnrollResponse(BaseModel):
652
+ id: str
653
+ """
654
+ ID of the factor that was just enrolled (in an unverified state).
655
+ """
656
+ type: Literal["totp", "phone"]
657
+ """
658
+ Type of MFA factor. Only `totp` supported for now.
659
+ """
660
+ totp: AuthMFAEnrollResponseTotp | None = None
661
+ """
662
+ TOTP enrollment information.
663
+ """
664
+ model_config = ConfigDict(arbitrary_types_allowed=True)
665
+ friendly_name: str
666
+ """
667
+ Friendly name of the factor, useful for distinguishing between factors
668
+ """
669
+ phone: str | None = None
670
+ """
671
+ Phone number of the MFA factor in E.164 format. Used to send messages
672
+ """
673
+
674
+ @model_validator(mode="after")
675
+ def validate_phone_required_for_phone_type(self) -> AuthMFAEnrollResponse:
676
+ if self.type == "phone" and not self.phone:
677
+ raise ValueError("phone is required when type is 'phone'")
678
+ return self
679
+
680
+
681
+ class AuthMFAUnenrollResponse(BaseModel):
682
+ id: str
683
+ """
684
+ ID of the factor that was successfully unenrolled.
685
+ """
686
+
687
+
688
+ class AuthMFAChallengeResponse(BaseModel):
689
+ id: str
690
+ """
691
+ ID of the newly created challenge.
692
+ """
693
+ expires_at: int
694
+ """
695
+ Timestamp in UNIX seconds when this challenge will no longer be usable.
696
+ """
697
+ factor_type: Literal["totp", "phone"] | None = Field(
698
+ validation_alias="type", default=None
699
+ )
700
+ """
701
+ Factor Type which generated the challenge
702
+ """
703
+
704
+
705
+ class AuthMFAListFactorsResponse(BaseModel):
706
+ all: list[Factor]
707
+ """
708
+ All available factors (verified and unverified).
709
+ """
710
+ totp: list[Factor]
711
+ """
712
+ Only verified TOTP factors. (A subset of `all`.)
713
+ """
714
+ phone: list[Factor]
715
+ """
716
+ Only verified Phone factors. (A subset of `all`.)
717
+ """
718
+
719
+
720
+ AuthenticatorAssuranceLevels = Literal["aal1", "aal2"]
721
+
722
+
723
+ class AuthMFAGetAuthenticatorAssuranceLevelResponse(BaseModel):
724
+ current_level: AuthenticatorAssuranceLevels | None = None
725
+ """
726
+ Current AAL level of the session.
727
+ """
728
+ next_level: AuthenticatorAssuranceLevels | None = None
729
+ """
730
+ Next possible AAL level for the session. If the next level is higher
731
+ than the current one, the user should go through MFA.
732
+ """
733
+ current_authentication_methods: list[AMREntry]
734
+ """
735
+ A list of all authentication methods attached to this session. Use
736
+ the information here to detect the last time a user verified a
737
+ factor, for example if implementing a step-up scenario.
738
+ """
739
+
740
+
741
+ class AuthMFAAdminDeleteFactorResponse(BaseModel):
742
+ id: str
743
+ """
744
+ ID of the factor that was successfully deleted.
745
+ """
746
+
747
+
748
+ class AuthMFAAdminDeleteFactorParams(TypedDict):
749
+ id: str
750
+ """
751
+ ID of the MFA factor to delete.
752
+ """
753
+ user_id: str
754
+ """
755
+ ID of the user whose factor is being deleted.
756
+ """
757
+
758
+
759
+ AuthMFAAdminListFactorsResponse = list[Factor]
760
+
761
+ AuthMFAAdminListFactorsResponseParser: TypeAdapter[AuthMFAAdminListFactorsResponse] = (
762
+ TypeAdapter(AuthMFAAdminListFactorsResponse)
763
+ )
764
+
765
+
766
+ class AuthMFAAdminListFactorsParams(TypedDict):
767
+ user_id: str
768
+ """
769
+ ID of the user for which to list all MFA factors.
770
+ """
771
+
772
+
773
+ class GenerateLinkProperties(BaseModel):
774
+ """
775
+ The properties related to the email link generated.
776
+ """
777
+
778
+ action_link: str
779
+ """
780
+ The email link to send to the user. The action_link follows the following format:
781
+
782
+ auth/v1/verify?type={verification_type}&token={hashed_token}&redirect_to={redirect_to}
783
+ """
784
+ email_otp: str
785
+ """
786
+ The raw email OTP.
787
+ You should send this in the email if you want your users to verify using an
788
+ OTP instead of the action link.
789
+ """
790
+ hashed_token: str
791
+ """
792
+ The hashed token appended to the action link.
793
+ """
794
+ redirect_to: str
795
+ """
796
+ The URL appended to the action link.
797
+ """
798
+ verification_type: GenerateLinkType
799
+ """
800
+ The verification type that the email link is associated to.
801
+ """
802
+
803
+
804
+ class GenerateLinkResponse(BaseModel):
805
+ properties: GenerateLinkProperties
806
+ user: User
807
+
808
+
809
+ class DecodedJWTDict(TypedDict):
810
+ exp: NotRequired[int]
811
+ aal: NotRequired[AuthenticatorAssuranceLevels | None]
812
+ amr: NotRequired[list[AMREntry] | None]
813
+
814
+
815
+ SignOutScope = Literal["global", "local", "others"]
816
+
817
+
818
+ class SignOutOptions(TypedDict):
819
+ scope: NotRequired[SignOutScope]
820
+
821
+
822
+ @with_config(ConfigDict(extra="allow"))
823
+ class JWTHeader(TypedDict):
824
+ alg: Literal["RS256", "ES256", "HS256"]
825
+ typ: NotRequired[str]
826
+ kid: NotRequired[str]
827
+
828
+
829
+ # TODO: useless, only kept for backwards compatibility
830
+ class RequiredClaims(TypedDict):
831
+ iss: str
832
+ sub: str
833
+ auth: str | list[str]
834
+ exp: int
835
+ iat: int
836
+ role: str
837
+ aal: AuthenticatorAssuranceLevels
838
+ session_id: str
839
+
840
+
841
+ @with_config(ConfigDict(extra="allow"))
842
+ class JWTPayload(TypedDict, total=False):
843
+ iss: str
844
+ sub: str
845
+ auth: str | list[str]
846
+ exp: int
847
+ iat: int
848
+ role: str
849
+ aal: AuthenticatorAssuranceLevels
850
+ session_id: str
851
+ amr: NotRequired[list[AMREntryDict]]
852
+
853
+
854
+ class ClaimsResponse(TypedDict):
855
+ claims: JWTPayload
856
+ headers: JWTHeader
857
+ signature: bytes
858
+
859
+
860
+ @with_config(ConfigDict(extra="allow"))
861
+ class JWK(TypedDict, total=False):
862
+ kty: Literal["RSA", "EC", "oct"]
863
+ key_ops: list[str]
864
+ alg: str | None
865
+ kid: str | None
866
+
867
+
868
+ class JWKSet(TypedDict):
869
+ keys: list[JWK]
870
+
871
+
872
+ OAuthClientGrantType = Literal["authorization_code", "refresh_token"]
873
+ """
874
+ OAuth client grant types supported by the OAuth 2.1 server.
875
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
876
+ """
877
+
878
+ OAuthClientResponseType = Literal["code"]
879
+ """
880
+ OAuth client response types supported by the OAuth 2.1 server.
881
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
882
+ """
883
+
884
+ OAuthClientType = Literal["public", "confidential"]
885
+ """
886
+ OAuth client type indicating whether the client can keep credentials confidential.
887
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
888
+ """
889
+
890
+ OAuthClientRegistrationType = Literal["dynamic", "manual"]
891
+ """
892
+ OAuth client registration type.
893
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
894
+ """
895
+
896
+ OAuthClientTokenEndpointAuthMethod = Literal[
897
+ "none", "client_secret_basic", "client_secret_post"
898
+ ]
899
+ """
900
+ OAuth client token endpoint authentication method.
901
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
902
+ """
903
+
904
+
905
+ class OAuthClient(BaseModel):
906
+ """
907
+ OAuth client object returned from the OAuth 2.1 server.
908
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
909
+ """
910
+
911
+ client_id: str
912
+ """Unique client identifier"""
913
+ client_name: str | None = None
914
+ """Human-readable name of the client application"""
915
+ client_secret: str | None = None
916
+ """Client secret for confidential clients (only returned on registration/regeneration)"""
917
+ client_type: OAuthClientType
918
+ """Type of the client"""
919
+ token_endpoint_auth_method: OAuthClientTokenEndpointAuthMethod
920
+ """Authentication method for the token endpoint"""
921
+ registration_type: OAuthClientRegistrationType
922
+ """Registration type of the client"""
923
+ client_uri: str | None = None
924
+ """URL of the client application's homepage"""
925
+ logo_uri: str | None = None
926
+ """URL of the client application's logo"""
927
+ redirect_uris: list[str]
928
+ """Array of redirect URIs used by the client"""
929
+ grant_types: list[OAuthClientGrantType]
930
+ """OAuth grant types the client is authorized to use"""
931
+ response_types: list[OAuthClientResponseType]
932
+ """OAuth response types the client can use"""
933
+ scope: str | None = None
934
+ """Space-separated list of scope values"""
935
+ created_at: str
936
+ """Timestamp when the client was created"""
937
+ updated_at: str
938
+ """Timestamp when the client was last updated"""
939
+
940
+
941
+ class CreateOAuthClientParams(BaseModel):
942
+ """
943
+ Parameters for creating a new OAuth client.
944
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
945
+ """
946
+
947
+ client_name: str
948
+ """Human-readable name of the OAuth client"""
949
+ client_uri: str | None = None
950
+ """URL of the client application's homepage"""
951
+ logo_uri: str | None = None
952
+ """URL of the client application's logo"""
953
+ redirect_uris: list[str]
954
+ """Array of redirect URIs used by the client"""
955
+ grant_types: list[OAuthClientGrantType] | None = None
956
+ """OAuth grant types the client is authorized to use (optional, defaults to authorization_code and refresh_token)"""
957
+ response_types: list[OAuthClientResponseType] | None = None
958
+ """OAuth response types the client can use (optional, defaults to code)"""
959
+ scope: str | None = None
960
+ """Space-separated list of scope values"""
961
+
962
+
963
+ class UpdateOAuthClientParams(BaseModel):
964
+ """
965
+ Parameters for updating an existing OAuth client.
966
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
967
+ """
968
+
969
+ client_name: str | None = None
970
+ """Human-readable name of the OAuth client"""
971
+ client_uri: str | None = None
972
+ """URI of the OAuth client"""
973
+ logo_uri: str | None = None
974
+ """URI of the OAuth client's logo"""
975
+ redirect_uris: list[str] | None = None
976
+ """Array of allowed redirect URIs"""
977
+ grant_types: list[OAuthClientGrantType] | None = None
978
+ """Array of allowed grant types"""
979
+
980
+
981
+ class OAuthClientResponse(BaseModel):
982
+ """
983
+ Response type for OAuth client operations.
984
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
985
+ """
986
+
987
+ client: OAuthClient | None = None
988
+
989
+
990
+ class Pagination(BaseModel):
991
+ """
992
+ Pagination information for list responses.
993
+ """
994
+
995
+ next_page: int | None = None
996
+ last_page: int = 0
997
+ total: int = 0
998
+
999
+
1000
+ class OAuthClientListResponse(BaseModel):
1001
+ """
1002
+ Response type for listing OAuth clients.
1003
+ Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1004
+ """
1005
+
1006
+ clients: list[OAuthClient] = Field(default_factory=list)
1007
+ aud: str | None = None
1008
+ next_page: int | None = None
1009
+ last_page: int = 0
1010
+ total: int = 0
1011
+
1012
+
1013
+ class PageParams(BaseModel):
1014
+ """
1015
+ Pagination parameters.
1016
+ """
1017
+
1018
+ page: int | None = None
1019
+ """Page number"""
1020
+ per_page: int | None = None
1021
+ """Number of items per page"""