workos 1.13.0__py3-none-any.whl → 5.38.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 (152) hide show
  1. workos/__about__.py +1 -1
  2. workos/__init__.py +3 -7
  3. workos/_base_client.py +138 -0
  4. workos/_client_configuration.py +10 -0
  5. workos/api_keys.py +53 -0
  6. workos/async_client.py +144 -0
  7. workos/audit_logs.py +125 -0
  8. workos/client.py +105 -20
  9. workos/directory_sync.py +369 -146
  10. workos/events.py +111 -0
  11. workos/exceptions.py +53 -26
  12. workos/fga.py +649 -0
  13. workos/mfa.py +152 -116
  14. workos/organization_domains.py +179 -0
  15. workos/organizations.py +401 -86
  16. workos/passwordless.py +67 -43
  17. workos/pipes.py +93 -0
  18. workos/portal.py +51 -28
  19. workos/session.py +337 -0
  20. workos/sso.py +305 -149
  21. workos/types/__init__.py +4 -0
  22. workos/types/api_keys/__init__.py +1 -0
  23. workos/types/api_keys/api_keys.py +20 -0
  24. workos/types/audit_logs/__init__.py +6 -0
  25. workos/types/audit_logs/audit_log_event.py +16 -0
  26. workos/types/audit_logs/audit_log_event_actor.py +12 -0
  27. workos/types/audit_logs/audit_log_event_context.py +8 -0
  28. workos/types/audit_logs/audit_log_event_target.py +12 -0
  29. workos/types/audit_logs/audit_log_export.py +18 -0
  30. workos/types/audit_logs/audit_log_metadata.py +4 -0
  31. workos/types/directory_sync/__init__.py +5 -0
  32. workos/types/directory_sync/directory.py +31 -0
  33. workos/types/directory_sync/directory_group.py +16 -0
  34. workos/types/directory_sync/directory_state.py +28 -0
  35. workos/types/directory_sync/directory_type.py +24 -0
  36. workos/types/directory_sync/directory_user.py +50 -0
  37. workos/types/directory_sync/list_filters.py +21 -0
  38. workos/types/events/__init__.py +13 -0
  39. workos/types/events/authentication_payload.py +70 -0
  40. workos/types/events/connection_payload_with_legacy_fields.py +5 -0
  41. workos/types/events/directory_group_membership_payload.py +9 -0
  42. workos/types/events/directory_group_with_previous_attributes.py +6 -0
  43. workos/types/events/directory_payload.py +16 -0
  44. workos/types/events/directory_payload_with_legacy_fields.py +29 -0
  45. workos/types/events/directory_user_with_previous_attributes.py +6 -0
  46. workos/types/events/event.py +324 -0
  47. workos/types/events/event_model.py +103 -0
  48. workos/types/events/event_type.py +59 -0
  49. workos/types/events/list_filters.py +10 -0
  50. workos/types/events/organization_domain_verification_failed_payload.py +14 -0
  51. workos/types/events/previous_attributes.py +3 -0
  52. workos/types/events/session_payload.py +27 -0
  53. workos/types/feature_flags/__init__.py +3 -0
  54. workos/types/feature_flags/feature_flag.py +12 -0
  55. workos/types/feature_flags/list_filters.py +5 -0
  56. workos/types/fga/__init__.py +5 -0
  57. workos/types/fga/authorization_resource_types.py +9 -0
  58. workos/types/fga/authorization_resources.py +10 -0
  59. workos/types/fga/check.py +51 -0
  60. workos/types/fga/list_filters.py +24 -0
  61. workos/types/fga/warnings.py +33 -0
  62. workos/types/fga/warrant.py +49 -0
  63. workos/types/list_resource.py +198 -0
  64. workos/types/metadata.py +4 -0
  65. workos/types/mfa/__init__.py +5 -0
  66. workos/types/mfa/authentication_challenge.py +14 -0
  67. workos/types/mfa/authentication_challenge_verification_response.py +9 -0
  68. workos/types/mfa/authentication_factor.py +70 -0
  69. workos/types/mfa/authentication_factor_totp_and_challenge_response.py +10 -0
  70. workos/types/mfa/enroll_authentication_factor_type.py +8 -0
  71. workos/types/organization_domains/__init__.py +1 -0
  72. workos/types/organization_domains/organization_domain.py +18 -0
  73. workos/types/organizations/__init__.py +6 -0
  74. workos/types/organizations/domain_data_input.py +7 -0
  75. workos/types/organizations/list_filters.py +6 -0
  76. workos/types/organizations/organization.py +13 -0
  77. workos/types/organizations/organization_common.py +12 -0
  78. workos/types/passwordless/__init__.py +2 -0
  79. workos/types/passwordless/passwordless_session.py +12 -0
  80. workos/types/passwordless/passwordless_session_type.py +3 -0
  81. workos/types/pipes/__init__.py +6 -0
  82. workos/types/pipes/pipes.py +34 -0
  83. workos/types/portal/__init__.py +2 -0
  84. workos/types/portal/portal_link.py +7 -0
  85. workos/types/portal/portal_link_intent.py +11 -0
  86. workos/types/portal/portal_link_intent_options.py +9 -0
  87. workos/types/roles/__init__.py +0 -0
  88. workos/types/roles/role.py +27 -0
  89. workos/types/sso/__init__.py +4 -0
  90. workos/types/sso/connection.py +70 -0
  91. workos/types/sso/connection_domain.py +8 -0
  92. workos/types/sso/profile.py +35 -0
  93. workos/types/sso/sso_provider_type.py +10 -0
  94. workos/types/user_management/__init__.py +12 -0
  95. workos/types/user_management/authenticate_with_common.py +66 -0
  96. workos/types/user_management/authentication_response.py +53 -0
  97. workos/types/user_management/email_verification.py +18 -0
  98. workos/types/user_management/impersonator.py +8 -0
  99. workos/types/user_management/invitation.py +26 -0
  100. workos/types/user_management/list_filters.py +29 -0
  101. workos/types/user_management/magic_auth.py +18 -0
  102. workos/types/user_management/oauth_tokens.py +21 -0
  103. workos/types/user_management/organization_membership.py +25 -0
  104. workos/types/user_management/password_hash_type.py +4 -0
  105. workos/types/user_management/password_reset.py +18 -0
  106. workos/types/user_management/screen_hint.py +3 -0
  107. workos/types/user_management/session.py +79 -0
  108. workos/types/user_management/user.py +22 -0
  109. workos/types/user_management/user_management_provider_type.py +11 -0
  110. workos/types/vault/__init__.py +2 -0
  111. workos/types/vault/key.py +25 -0
  112. workos/types/vault/object.py +38 -0
  113. workos/types/webhooks/__init__.py +0 -0
  114. workos/types/webhooks/webhook.py +330 -0
  115. workos/types/webhooks/webhook_model.py +14 -0
  116. workos/types/webhooks/webhook_payload.py +4 -0
  117. workos/types/widgets/__init__.py +2 -0
  118. workos/types/widgets/widget_scope.py +4 -0
  119. workos/types/widgets/widget_token_response.py +7 -0
  120. workos/types/workos_model.py +26 -0
  121. workos/typing/__init__.py +1 -0
  122. workos/typing/literals.py +32 -0
  123. workos/typing/sync_or_async.py +5 -0
  124. workos/typing/untyped_literal.py +37 -0
  125. workos/typing/webhooks.py +18 -0
  126. workos/user_management.py +2400 -0
  127. workos/utils/_base_http_client.py +252 -0
  128. workos/utils/crypto_provider.py +39 -0
  129. workos/utils/http_client.py +214 -0
  130. workos/utils/pagination_order.py +4 -0
  131. workos/utils/request_helper.py +27 -0
  132. workos/vault.py +544 -0
  133. workos/webhooks.py +96 -39
  134. workos/widgets.py +55 -0
  135. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/LICENSE +1 -1
  136. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/METADATA +47 -22
  137. workos-5.38.0.dist-info/RECORD +141 -0
  138. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/WHEEL +1 -1
  139. workos/audit_trail.py +0 -179
  140. workos/resources/base.py +0 -36
  141. workos/resources/directory_sync.py +0 -28
  142. workos/resources/event.py +0 -42
  143. workos/resources/event_action.py +0 -11
  144. workos/resources/mfa.py +0 -32
  145. workos/resources/sso.py +0 -53
  146. workos/utils/connection_types.py +0 -35
  147. workos/utils/pagiantion_order.py +0 -6
  148. workos/utils/request.py +0 -100
  149. workos/utils/validation.py +0 -60
  150. workos-1.13.0.dist-info/RECORD +0 -29
  151. /workos/{resources/__init__.py → py.typed} +0 -0
  152. {workos-1.13.0.dist-info → workos-5.38.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,2400 @@
1
+ from typing import Awaitable, Optional, Protocol, Sequence, Type, Union, cast
2
+ from urllib.parse import urlencode
3
+ from workos._client_configuration import ClientConfiguration
4
+ from workos.session import AsyncSession, Session
5
+ from workos.types.feature_flags import FeatureFlag
6
+ from workos.types.feature_flags.list_filters import FeatureFlagListFilters
7
+ from workos.types.list_resource import (
8
+ ListArgs,
9
+ ListMetadata,
10
+ ListPage,
11
+ WorkOSListResource,
12
+ )
13
+ from workos.types.metadata import Metadata
14
+ from workos.types.mfa import (
15
+ AuthenticationFactor,
16
+ AuthenticationFactorTotpAndChallengeResponse,
17
+ AuthenticationFactorType,
18
+ )
19
+ from workos.types.user_management import (
20
+ AuthenticationResponse,
21
+ EmailVerification,
22
+ Invitation,
23
+ MagicAuth,
24
+ OrganizationMembership,
25
+ OrganizationMembershipStatus,
26
+ PasswordReset,
27
+ RefreshTokenAuthenticationResponse,
28
+ User,
29
+ )
30
+ from workos.types.user_management.authenticate_with_common import (
31
+ AuthenticateWithCodeParameters,
32
+ AuthenticateWithEmailVerificationParameters,
33
+ AuthenticateWithMagicAuthParameters,
34
+ AuthenticateWithOrganizationSelectionParameters,
35
+ AuthenticateWithParameters,
36
+ AuthenticateWithPasswordParameters,
37
+ AuthenticateWithRefreshTokenParameters,
38
+ AuthenticateWithTotpParameters,
39
+ )
40
+ from workos.types.user_management.authentication_response import (
41
+ AuthKitAuthenticationResponse,
42
+ AuthenticationResponseType,
43
+ )
44
+ from workos.types.user_management.list_filters import (
45
+ AuthenticationFactorsListFilters,
46
+ InvitationsListFilters,
47
+ OrganizationMembershipsListFilters,
48
+ UsersListFilters,
49
+ )
50
+ from workos.types.user_management.password_hash_type import PasswordHashType
51
+ from workos.types.user_management.screen_hint import ScreenHintType
52
+ from workos.types.user_management.session import SessionConfig
53
+ from workos.types.user_management.session import Session as UserManagementSession
54
+ from workos.types.user_management.user_management_provider_type import (
55
+ UserManagementProviderType,
56
+ )
57
+ from workos.typing.sync_or_async import SyncOrAsync
58
+ from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient
59
+ from workos.utils.pagination_order import PaginationOrder
60
+ from workos.utils.request_helper import (
61
+ DEFAULT_LIST_RESPONSE_LIMIT,
62
+ RESPONSE_TYPE_CODE,
63
+ REQUEST_METHOD_POST,
64
+ REQUEST_METHOD_GET,
65
+ REQUEST_METHOD_DELETE,
66
+ REQUEST_METHOD_PUT,
67
+ QueryParameters,
68
+ RequestHelper,
69
+ )
70
+
71
+ USER_PATH = "user_management/users"
72
+ USER_DETAIL_PATH = "user_management/users/{0}"
73
+ USER_DETAIL_BY_EXTERNAL_ID_PATH = "user_management/users/external_id/{0}"
74
+ ORGANIZATION_MEMBERSHIP_PATH = "user_management/organization_memberships"
75
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH = "user_management/organization_memberships/{0}"
76
+ ORGANIZATION_MEMBERSHIP_DEACTIVATE_PATH = (
77
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH + "/deactivate"
78
+ )
79
+ ORGANIZATION_MEMBERSHIP_REACTIVATE_PATH = (
80
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH + "/reactivate"
81
+ )
82
+ USER_AUTHORIZATION_PATH = "user_management/authorize"
83
+ USER_AUTHENTICATE_PATH = "user_management/authenticate"
84
+ USER_SEND_PASSWORD_RESET_PATH = "user_management/password_reset/send"
85
+ USER_RESET_PASSWORD_PATH = "user_management/password_reset/confirm"
86
+ USER_SEND_VERIFICATION_EMAIL_PATH = "user_management/users/{0}/email_verification/send"
87
+ USER_VERIFY_EMAIL_CODE_PATH = "user_management/users/{0}/email_verification/confirm"
88
+ MAGIC_AUTH_DETAIL_PATH = "user_management/magic_auth/{0}"
89
+ MAGIC_AUTH_PATH = "user_management/magic_auth"
90
+ USER_SEND_MAGIC_AUTH_PATH = "user_management/magic_auth/send"
91
+ USER_AUTH_FACTORS_PATH = "user_management/users/{0}/auth_factors"
92
+ USER_SESSIONS_PATH = "user_management/users/{0}/sessions"
93
+ SESSIONS_REVOKE_PATH = "user_management/sessions/revoke"
94
+ EMAIL_VERIFICATION_DETAIL_PATH = "user_management/email_verification/{0}"
95
+ INVITATION_PATH = "user_management/invitations"
96
+ INVITATION_DETAIL_PATH = "user_management/invitations/{0}"
97
+ INVITATION_DETAIL_BY_TOKEN_PATH = "user_management/invitations/by_token/{0}"
98
+ INVITATION_REVOKE_PATH = "user_management/invitations/{0}/revoke"
99
+ INVITATION_RESEND_PATH = "user_management/invitations/{0}/resend"
100
+ PASSWORD_RESET_PATH = "user_management/password_reset"
101
+ PASSWORD_RESET_DETAIL_PATH = "user_management/password_reset/{0}"
102
+ USER_FEATURE_FLAGS_PATH = "user_management/users/{0}/feature-flags"
103
+
104
+
105
+ UsersListResource = WorkOSListResource[User, UsersListFilters, ListMetadata]
106
+
107
+ OrganizationMembershipsListResource = WorkOSListResource[
108
+ OrganizationMembership, OrganizationMembershipsListFilters, ListMetadata
109
+ ]
110
+
111
+ AuthenticationFactorsListResource = WorkOSListResource[
112
+ AuthenticationFactor, AuthenticationFactorsListFilters, ListMetadata
113
+ ]
114
+
115
+ InvitationsListResource = WorkOSListResource[
116
+ Invitation, InvitationsListFilters, ListMetadata
117
+ ]
118
+
119
+ FeatureFlagsListResource = WorkOSListResource[
120
+ FeatureFlag, FeatureFlagListFilters, ListMetadata
121
+ ]
122
+
123
+ from workos.types.user_management.list_filters import SessionsListFilters
124
+
125
+ SessionsListResource = WorkOSListResource[
126
+ UserManagementSession, SessionsListFilters, ListMetadata
127
+ ]
128
+
129
+
130
+ class UserManagementModule(Protocol):
131
+ """Offers methods for using the WorkOS User Management API."""
132
+
133
+ _client_configuration: ClientConfiguration
134
+
135
+ def load_sealed_session(
136
+ self, *, sealed_session: str, cookie_password: str
137
+ ) -> Union[Session, Awaitable[AsyncSession]]:
138
+ """Load a sealed session and return the session data.
139
+
140
+ Args:
141
+ sealed_session (str): The sealed session data to load.
142
+ cookie_password (str): The cookie password to use to decrypt the session data.
143
+
144
+ Returns:
145
+ Session: The session module.
146
+ """
147
+ ...
148
+
149
+ def get_user(self, user_id: str) -> SyncOrAsync[User]:
150
+ """Get the details of an existing user.
151
+
152
+ Args:
153
+ user_id (str): User unique identifier
154
+ Returns:
155
+ User: User response from WorkOS.
156
+ """
157
+ ...
158
+
159
+ def get_user_by_external_id(self, external_id: str) -> SyncOrAsync[User]:
160
+ """Get the details of an existing user by external id.
161
+
162
+ Args:
163
+ external_id (str): User's external id
164
+ Returns:
165
+ User: User response from WorkOS.
166
+ """
167
+ ...
168
+
169
+ def list_users(
170
+ self,
171
+ *,
172
+ email: Optional[str] = None,
173
+ organization_id: Optional[str] = None,
174
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
175
+ before: Optional[str] = None,
176
+ after: Optional[str] = None,
177
+ order: PaginationOrder = "desc",
178
+ ) -> SyncOrAsync[UsersListResource]:
179
+ """Get a list of all of your existing users matching the criteria specified.
180
+
181
+ Kwargs:
182
+ email (str): Filter Users by their email. (Optional)
183
+ organization_id (str): Filter Users by the organization they are members of. (Optional)
184
+ limit (int): Maximum number of records to return. (Optional)
185
+ before (str): Pagination cursor to receive records before a provided User ID. (Optional)
186
+ after (str): Pagination cursor to receive records after a provided User ID. (Optional)
187
+ order (Literal["asc","desc"]): Sort records in either ascending or descending (default) order by created_at timestamp. (Optional)
188
+
189
+ Returns:
190
+ UsersListResource: Users response from WorkOS.
191
+ """
192
+ ...
193
+
194
+ def create_user(
195
+ self,
196
+ *,
197
+ email: str,
198
+ password: Optional[str] = None,
199
+ password_hash: Optional[str] = None,
200
+ password_hash_type: Optional[PasswordHashType] = None,
201
+ first_name: Optional[str] = None,
202
+ last_name: Optional[str] = None,
203
+ email_verified: Optional[bool] = None,
204
+ external_id: Optional[str] = None,
205
+ metadata: Optional[Metadata] = None,
206
+ ) -> SyncOrAsync[User]:
207
+ """Create a new user.
208
+
209
+ Kwargs:
210
+ email (str): The email address of the user.
211
+ password (str): The password to set for the user. (Optional)
212
+ password_hash (str): The hashed password to set for the user. Mutually exclusive with password. (Optional)
213
+ password_hash_type (str): The algorithm originally used to hash the password, used when providing a password_hash. Valid values are 'bcrypt', `firebase-scrypt`, and `ssha`. (Optional)
214
+ first_name (str): The user's first name. (Optional)
215
+ last_name (str): The user's last name. (Optional)
216
+ email_verified (bool): Whether the user's email address was previously verified. (Optional)
217
+
218
+ Returns:
219
+ User: Created User response from WorkOS.
220
+ """
221
+ ...
222
+
223
+ def update_user(
224
+ self,
225
+ *,
226
+ user_id: str,
227
+ email: Optional[str] = None,
228
+ first_name: Optional[str] = None,
229
+ last_name: Optional[str] = None,
230
+ email_verified: Optional[bool] = None,
231
+ password: Optional[str] = None,
232
+ password_hash: Optional[str] = None,
233
+ password_hash_type: Optional[PasswordHashType] = None,
234
+ external_id: Optional[str] = None,
235
+ metadata: Optional[Metadata] = None,
236
+ locale: Optional[str] = None,
237
+ ) -> SyncOrAsync[User]:
238
+ """Update user attributes.
239
+
240
+ Kwargs:
241
+ user_id (str): The User unique identifier
242
+ first_name (str): The user's first name. (Optional)
243
+ last_name (str): The user's last name. (Optional)
244
+ email (str): The user's email. (Optional)
245
+ email_verified (bool): Whether the user's email address was previously verified. (Optional)
246
+ password (str): The password to set for the user. (Optional)
247
+ password_hash (str): The hashed password to set for the user, used when migrating from another user store. Mutually exclusive with password. (Optional)
248
+ password_hash_type (str): The algorithm originally used to hash the password, used when providing a password_hash. Valid values are 'bcrypt', `firebase-scrypt`, and `ssha`. (Optional)
249
+ locale (str): The user's locale. (Optional)
250
+
251
+ Returns:
252
+ User: Updated User response from WorkOS.
253
+ """
254
+ ...
255
+
256
+ def delete_user(self, user_id: str) -> SyncOrAsync[None]:
257
+ """Delete an existing user.
258
+
259
+ Args:
260
+ user_id (str): User unique identifier
261
+ Returns:
262
+ None
263
+ """
264
+ ...
265
+
266
+ def create_organization_membership(
267
+ self,
268
+ *,
269
+ user_id: str,
270
+ organization_id: str,
271
+ role_slug: Optional[str] = None,
272
+ role_slugs: Optional[Sequence[str]] = None,
273
+ ) -> SyncOrAsync[OrganizationMembership]:
274
+ """Create a new OrganizationMembership for the given Organization and User.
275
+
276
+ Kwargs:
277
+ user_id: The unique ID of the User.
278
+ organization_id: The unique ID of the Organization to which the user belongs to.
279
+ role_slug: The unique slug of the role to grant to this membership.(Optional)
280
+ role_slugs: The unique slugs of the roles to grant to this membership.(Optional)
281
+
282
+ Note:
283
+ role_slug and role_slugs are mutually exclusive. If neither is provided,
284
+ the user will be assigned the organization's default role.
285
+
286
+ Returns:
287
+ OrganizationMembership: Created OrganizationMembership response from WorkOS.
288
+ """
289
+ ...
290
+
291
+ def update_organization_membership(
292
+ self,
293
+ *,
294
+ organization_membership_id: str,
295
+ role_slug: Optional[str] = None,
296
+ role_slugs: Optional[Sequence[str]] = None,
297
+ ) -> SyncOrAsync[OrganizationMembership]:
298
+ """Updates an OrganizationMembership for the given id.
299
+
300
+ Args:
301
+ organization_membership_id (str): The unique ID of the Organization Membership.
302
+ role_slug: The unique slug of the role to grant to this membership.(Optional)
303
+ role_slugs: The unique slugs of the roles to grant to this membership.(Optional)
304
+
305
+ Note:
306
+ role_slug and role_slugs are mutually exclusive. If neither is provided,
307
+ the role(s) of the membership will remain unchanged.
308
+
309
+ Returns:
310
+ OrganizationMembership: Updated OrganizationMembership response from WorkOS.
311
+ """
312
+ ...
313
+
314
+ def get_organization_membership(
315
+ self, organization_membership_id: str
316
+ ) -> SyncOrAsync[OrganizationMembership]:
317
+ """Get the details of an organization membership.
318
+
319
+ Args:
320
+ organization_membership_id (str): The unique ID of the Organization Membership.
321
+ Returns:
322
+ OrganizationMembership: OrganizationMembership response from WorkOS.
323
+ """
324
+ ...
325
+
326
+ def list_organization_memberships(
327
+ self,
328
+ *,
329
+ user_id: Optional[str] = None,
330
+ organization_id: Optional[str] = None,
331
+ statuses: Optional[Sequence[OrganizationMembershipStatus]] = None,
332
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
333
+ before: Optional[str] = None,
334
+ after: Optional[str] = None,
335
+ order: PaginationOrder = "desc",
336
+ ) -> SyncOrAsync[OrganizationMembershipsListResource]:
337
+ """Get a list of all of your existing organization memberships matching the criteria specified.
338
+
339
+ Kwargs:
340
+ user_id (str): Filter Organization Memberships by user. (Optional)
341
+ organization_id (str): Filter Organization Memberships by organization. (Optional)
342
+ statuses (Sequence[OrganizationMembershipStatus]): Filter Organization Memberships by status. (Optional)
343
+ limit (int): Maximum number of records to return. (Optional)
344
+ before (str): Pagination cursor to receive records before a provided Organization Membership ID. (Optional)
345
+ after (str): Pagination cursor to receive records after a provided Organization Membership ID. (Optional)
346
+ order (Literal["asc","desc"]): Sort records in either ascending or descending (default) order by created_at timestamp. (Optional)
347
+
348
+ Returns:
349
+ OrganizationMembershipsListResource: Organization Memberships response from WorkOS.
350
+ """
351
+ ...
352
+
353
+ def delete_organization_membership(
354
+ self, organization_membership_id: str
355
+ ) -> SyncOrAsync[None]:
356
+ """Delete an existing organization membership.
357
+
358
+ Args:
359
+ organization_membership_id (str): The unique ID of the Organization Membership.
360
+ Returns:
361
+ None
362
+ """
363
+ ...
364
+
365
+ def deactivate_organization_membership(
366
+ self, organization_membership_id: str
367
+ ) -> SyncOrAsync[OrganizationMembership]:
368
+ """Deactivate an organization membership.
369
+
370
+ Args:
371
+ organization_membership_id (str): The unique ID of the Organization Membership.
372
+ Returns:
373
+ OrganizationMembership: OrganizationMembership response from WorkOS.
374
+ """
375
+ ...
376
+
377
+ def reactivate_organization_membership(
378
+ self, organization_membership_id: str
379
+ ) -> SyncOrAsync[OrganizationMembership]:
380
+ """Reactivates an organization membership.
381
+
382
+ Args:
383
+ organization_membership_id (str): The unique ID of the Organization Membership.
384
+ Returns:
385
+ OrganizationMembership: OrganizationMembership response from WorkOS.
386
+ """
387
+ ...
388
+
389
+ def get_authorization_url(
390
+ self,
391
+ *,
392
+ redirect_uri: str,
393
+ domain_hint: Optional[str] = None,
394
+ login_hint: Optional[str] = None,
395
+ state: Optional[str] = None,
396
+ provider: Optional[UserManagementProviderType] = None,
397
+ provider_scopes: Optional[Sequence[str]] = None,
398
+ connection_id: Optional[str] = None,
399
+ organization_id: Optional[str] = None,
400
+ code_challenge: Optional[str] = None,
401
+ prompt: Optional[str] = None,
402
+ screen_hint: Optional[ScreenHintType] = None,
403
+ ) -> str:
404
+ """Generate an OAuth 2.0 authorization URL.
405
+
406
+ The URL generated will redirect a User to the Identity Provider configured through
407
+ WorkOS.
408
+
409
+ This method is purposefully designed as synchronous as it does not make any HTTP requests.
410
+
411
+ Kwargs:
412
+ redirect_uri (str): A Redirect URI to return an authorized user to.
413
+ connection_id (str): The connection_id connection selector is used to initiate SSO for a Connection.
414
+ The value of this parameter should be a WorkOS Connection ID. (Optional)
415
+ organization_id (str): The organization_id connection selector is used to initiate SSO for an Organization.
416
+ The value of this parameter should be a WorkOS Organization ID. (Optional)
417
+ provider (UserManagementProviderType): The provider connection selector is used to initiate SSO using an OAuth-compatible provider.
418
+ Currently, the supported values for provider are 'authkit', 'AppleOAuth', 'GitHubOAuth, 'GoogleOAuth', 'MicrosoftOAuth', and 'SalesforceOAuth'. (Optional)
419
+ provider_scopes (Sequence[str]): Can be used to specify additional scopes that will be requested when initiating SSO using an OAuth provider. (Optional)
420
+ domain_hint (str): Can be used to pre-fill the domain field when initiating authentication with Microsoft OAuth,
421
+ or with a GoogleSAML connection type. (Optional)
422
+ login_hint (str): Can be used to pre-fill the username/email address field of the IdP sign-in page for the user,
423
+ if you know their username ahead of time. Currently, this parameter is supported for OAuth, OpenID Connect,
424
+ OktaSAML, and AzureSAML connection types. (Optional)
425
+ state (str): An encoded string passed to WorkOS that'd be preserved through the authentication workflow, passed
426
+ back as a query parameter. (Optional)
427
+ code_challenge (str): Code challenge is derived from the code verifier used for the PKCE flow. (Optional)
428
+ prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
429
+ consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
430
+ 'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
431
+ screen_hint (ScreenHintType): Specify which AuthKit screen users should land on upon redirection (Only applicable when provider is 'authkit').
432
+
433
+ Returns:
434
+ str: URL to redirect a User to to begin the OAuth workflow with WorkOS
435
+ """
436
+ params: QueryParameters = {
437
+ "client_id": self._client_configuration.client_id,
438
+ "redirect_uri": redirect_uri,
439
+ "response_type": RESPONSE_TYPE_CODE,
440
+ }
441
+
442
+ if connection_id is None and organization_id is None and provider is None:
443
+ raise ValueError(
444
+ "Incomplete arguments. Need to specify either a 'connection_id', 'organization_id', or 'provider_id'"
445
+ )
446
+
447
+ if connection_id is not None:
448
+ params["connection_id"] = connection_id
449
+ if organization_id is not None:
450
+ params["organization_id"] = organization_id
451
+ if provider is not None:
452
+ params["provider"] = provider
453
+ if provider_scopes is not None:
454
+ params["provider_scopes"] = ",".join(provider_scopes)
455
+ if domain_hint is not None:
456
+ params["domain_hint"] = domain_hint
457
+ if login_hint is not None:
458
+ params["login_hint"] = login_hint
459
+ if state is not None:
460
+ params["state"] = state
461
+ if code_challenge:
462
+ params["code_challenge"] = code_challenge
463
+ params["code_challenge_method"] = "S256"
464
+ if prompt is not None:
465
+ params["prompt"] = prompt
466
+ if screen_hint is not None:
467
+ params["screen_hint"] = screen_hint
468
+
469
+ return RequestHelper.build_url_with_query_params(
470
+ base_url=self._client_configuration.base_url,
471
+ path=USER_AUTHORIZATION_PATH,
472
+ **params,
473
+ )
474
+
475
+ def _authenticate_with(
476
+ self,
477
+ payload: AuthenticateWithParameters,
478
+ response_model: Type[AuthenticationResponseType],
479
+ ) -> SyncOrAsync[AuthenticationResponseType]: ...
480
+
481
+ def authenticate_with_password(
482
+ self,
483
+ *,
484
+ email: str,
485
+ password: str,
486
+ ip_address: Optional[str] = None,
487
+ user_agent: Optional[str] = None,
488
+ ) -> SyncOrAsync[AuthenticationResponse]:
489
+ """Authenticates a user with email and password.
490
+
491
+ Kwargs:
492
+ email (str): The email address of the user.
493
+ password (str): The password of the user.
494
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
495
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
496
+
497
+ Returns:
498
+ AuthenticationResponse: Authentication response from WorkOS.
499
+ """
500
+ ...
501
+
502
+ def authenticate_with_code(
503
+ self,
504
+ *,
505
+ code: str,
506
+ session: Optional[SessionConfig] = None,
507
+ code_verifier: Optional[str] = None,
508
+ ip_address: Optional[str] = None,
509
+ user_agent: Optional[str] = None,
510
+ invitation_token: Optional[str] = None,
511
+ ) -> SyncOrAsync[AuthenticationResponse]:
512
+ """Authenticates an OAuth user or a user that is logging in through SSO.
513
+
514
+ Kwargs:
515
+ code (str): The authorization value which was passed back as a query parameter in the callback to the Redirect URI.
516
+ session (SessionConfig): Configuration for the session. (Optional)
517
+ code_verifier (str): The randomly generated string used to derive the code challenge that was passed to the authorization
518
+ url as part of the PKCE flow. This parameter is required when the client secret is not present. (Optional)
519
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
520
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
521
+ invitation_token (str): The token of an Invitation, if required. (Optional)
522
+
523
+ Returns:
524
+ AuthenticationResponse: Authentication response from WorkOS.
525
+ """
526
+
527
+ ...
528
+
529
+ def authenticate_with_magic_auth(
530
+ self,
531
+ *,
532
+ code: str,
533
+ email: str,
534
+ link_authorization_code: Optional[str] = None,
535
+ ip_address: Optional[str] = None,
536
+ user_agent: Optional[str] = None,
537
+ ) -> SyncOrAsync[AuthenticationResponse]:
538
+ """Authenticates a user by verifying a one-time code sent to the user's email address by the Magic Auth Send Code endpoint.
539
+
540
+ Kwargs:
541
+ code (str): The one-time code that was emailed to the user.
542
+ email (str): The email of the User who will be authenticated.
543
+ link_authorization_code (str): An authorization code used in a previous authenticate request that resulted in an existing user error response. (Optional)
544
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
545
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
546
+
547
+ Returns:
548
+ AuthenticationResponse: Authentication response from WorkOS.
549
+ """
550
+ ...
551
+
552
+ def authenticate_with_email_verification(
553
+ self,
554
+ *,
555
+ code: str,
556
+ pending_authentication_token: str,
557
+ ip_address: Optional[str] = None,
558
+ user_agent: Optional[str] = None,
559
+ ) -> SyncOrAsync[AuthenticationResponse]:
560
+ """Authenticates a user that requires email verification by verifying a one-time code sent to the user's email address and the pending authentication token.
561
+
562
+ Kwargs:
563
+ code (str): The one-time code that was emailed to the user.
564
+ pending_authentication_token (str): The token returned from an authentication attempt due to an unverified email address.
565
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
566
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
567
+
568
+ Returns:
569
+ AuthenticationResponse: Authentication response from WorkOS.
570
+ """
571
+ ...
572
+
573
+ def authenticate_with_totp(
574
+ self,
575
+ *,
576
+ code: str,
577
+ authentication_challenge_id: str,
578
+ pending_authentication_token: str,
579
+ ip_address: Optional[str] = None,
580
+ user_agent: Optional[str] = None,
581
+ ) -> SyncOrAsync[AuthenticationResponse]:
582
+ """Authenticates a user that has MFA enrolled by verifying the TOTP code, the Challenge from the Factor, and the pending authentication token.
583
+
584
+ Kwargs:
585
+ code (str): The time-based-one-time-password generated by the Factor that was challenged.
586
+ authentication_challenge_id (str): The unique ID of the authentication Challenge created for the TOTP Factor for which the user is enrolled.
587
+ pending_authentication_token (str): The token returned from a failed authentication attempt due to MFA challenge.
588
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
589
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
590
+
591
+ Returns:
592
+ AuthenticationResponse: Authentication response from WorkOS.
593
+ """
594
+ ...
595
+
596
+ def authenticate_with_organization_selection(
597
+ self,
598
+ *,
599
+ organization_id: str,
600
+ pending_authentication_token: str,
601
+ ip_address: Optional[str] = None,
602
+ user_agent: Optional[str] = None,
603
+ ) -> SyncOrAsync[AuthenticationResponse]:
604
+ """Authenticates a user that is a member of multiple organizations by verifying the organization ID and the pending authentication token.
605
+
606
+ Kwargs:
607
+ organization_id (str): The organization to authenticate for.
608
+ pending_authentication_token (str): The token returned from a failed authentication attempt due to organization selection being required.
609
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
610
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
611
+
612
+ Returns:
613
+ AuthenticationResponse: Authentication response from WorkOS.
614
+ """
615
+ ...
616
+
617
+ def authenticate_with_refresh_token(
618
+ self,
619
+ *,
620
+ refresh_token: str,
621
+ session: Optional[SessionConfig] = None,
622
+ organization_id: Optional[str] = None,
623
+ ip_address: Optional[str] = None,
624
+ user_agent: Optional[str] = None,
625
+ ) -> SyncOrAsync[RefreshTokenAuthenticationResponse]:
626
+ """Authenticates a user with a refresh token.
627
+
628
+ Kwargs:
629
+ refresh_token (str): The token associated to the user.
630
+ session (SessionConfig): Configuration for the session. (Optional)
631
+ organization_id (str): The organization to issue the new access token for. (Optional)
632
+ ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
633
+ user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
634
+
635
+ Returns:
636
+ RefreshTokenAuthenticationResponse: Refresh Token Authentication response from WorkOS.
637
+ """
638
+ ...
639
+
640
+ def get_jwks_url(self) -> str:
641
+ """Get the public key that is used for verifying access tokens.
642
+
643
+ This method is purposefully designed as synchronous as it does not make any HTTP requests.
644
+
645
+ Returns:
646
+ (str): The public JWKS URL.
647
+ """
648
+
649
+ return f"{self._client_configuration.base_url}sso/jwks/{self._client_configuration.client_id}"
650
+
651
+ def get_logout_url(self, session_id: str, return_to: Optional[str] = None) -> str:
652
+ """Get the URL for ending the session and redirecting the user
653
+
654
+ This method is purposefully designed as synchronous as it does not make any HTTP requests.
655
+
656
+ Args:
657
+ session_id (str): The ID of the user's session
658
+ return_to (str): The URL to redirect the user to after the session is ended. (Optional)
659
+
660
+ Returns:
661
+ (str): URL to redirect the user to to end the session.
662
+ """
663
+
664
+ params = {"session_id": session_id}
665
+
666
+ if return_to:
667
+ params["return_to"] = return_to
668
+
669
+ return f"{self._client_configuration.base_url}user_management/sessions/logout?{urlencode(params)}"
670
+
671
+ def get_password_reset(self, password_reset_id: str) -> SyncOrAsync[PasswordReset]:
672
+ """Get the details of a password reset object.
673
+
674
+ Args:
675
+ password_reset_id (str): The unique ID of the password reset object.
676
+
677
+ Returns:
678
+ PasswordReset: PasswordReset response from WorkOS.
679
+ """
680
+
681
+ ...
682
+
683
+ def create_password_reset(self, email: str) -> SyncOrAsync[PasswordReset]:
684
+ """Creates a password reset token that can be sent to a user's email to reset the password.
685
+
686
+ Args:
687
+ email: The email address of the user.
688
+
689
+ Returns:
690
+ PasswordReset: PasswordReset response from WorkOS.
691
+ """
692
+ ...
693
+
694
+ def reset_password(self, *, token: str, new_password: str) -> SyncOrAsync[User]:
695
+ """Resets user password using token that was sent to the user.
696
+
697
+ Kwargs:
698
+ token (str): The reset token emailed to the user.
699
+ new_password (str): The new password to be set for the user.
700
+
701
+ Returns:
702
+ User: User response from WorkOS.
703
+ """
704
+ ...
705
+
706
+ def get_email_verification(
707
+ self, email_verification_id: str
708
+ ) -> SyncOrAsync[EmailVerification]:
709
+ """Get the details of an email verification object.
710
+
711
+ Args:
712
+ email_verification_id (str): The unique ID of the email verification object.
713
+
714
+ Returns:
715
+ EmailVerification: EmailVerification response from WorkOS.
716
+ """
717
+ ...
718
+
719
+ def send_verification_email(self, user_id: str) -> SyncOrAsync[User]:
720
+ """Sends a verification email to the provided user.
721
+
722
+ Args:
723
+ user_id (str): The unique ID of the User whose email address will be verified.
724
+
725
+ Returns:
726
+ User: User response from WorkOS.
727
+ """
728
+ ...
729
+
730
+ def verify_email(self, *, user_id: str, code: str) -> SyncOrAsync[User]:
731
+ """Verifies user email using one-time code that was sent to the user.
732
+
733
+ Kwargs:
734
+ user_id (str): The unique ID of the User whose email address will be verified.
735
+ code (str): The one-time code emailed to the user.
736
+
737
+ Returns:
738
+ User: User response from WorkOS.
739
+ """
740
+ ...
741
+
742
+ def list_sessions(
743
+ self,
744
+ *,
745
+ user_id: str,
746
+ limit: Optional[int] = None,
747
+ before: Optional[str] = None,
748
+ after: Optional[str] = None,
749
+ order: Optional[PaginationOrder] = "desc",
750
+ ) -> SyncOrAsync["SessionsListResource"]: ...
751
+
752
+ def revoke_session(self, *, session_id: str) -> SyncOrAsync[None]: ...
753
+
754
+ def get_magic_auth(self, magic_auth_id: str) -> SyncOrAsync[MagicAuth]:
755
+ """Get the details of a Magic Auth object.
756
+
757
+ Args:
758
+ magic_auth_id (str): The unique ID of the Magic Auth object.
759
+
760
+ Returns:
761
+ MagicAuth: MagicAuth response from WorkOS.
762
+ """
763
+ ...
764
+
765
+ def create_magic_auth(
766
+ self, *, email: str, invitation_token: Optional[str] = None
767
+ ) -> SyncOrAsync[MagicAuth]:
768
+ """Creates a Magic Auth code challenge that can be sent to a user's email for authentication.
769
+
770
+ Kwargs:
771
+ email: The email address of the user.
772
+ invitation_token: The token of an Invitation, if required. (Optional)
773
+
774
+ Returns:
775
+ MagicAuth: MagicAuth response from WorkOS.
776
+ """
777
+ ...
778
+
779
+ def enroll_auth_factor(
780
+ self,
781
+ *,
782
+ user_id: str,
783
+ type: AuthenticationFactorType,
784
+ totp_issuer: Optional[str] = None,
785
+ totp_user: Optional[str] = None,
786
+ totp_secret: Optional[str] = None,
787
+ ) -> SyncOrAsync[AuthenticationFactorTotpAndChallengeResponse]:
788
+ """Enrolls a user in a new auth factor.
789
+
790
+ Kwargs:
791
+ user_id (str): The unique ID of the User to be enrolled in the auth factor.
792
+ type (str): The type of factor to enroll (Only option available is 'totp').
793
+ totp_issuer (str): Name of the Organization (Optional)
794
+ totp_user (str): Email of user (Optional)
795
+ totp_secret (str): The secret key for the TOTP factor. Generated if not provided. (Optional)
796
+
797
+ Returns:
798
+ AuthenticationFactorTotpAndChallengeResponse
799
+ """
800
+ ...
801
+
802
+ def list_auth_factors(
803
+ self,
804
+ *,
805
+ user_id: str,
806
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
807
+ before: Optional[str] = None,
808
+ after: Optional[str] = None,
809
+ order: PaginationOrder = "desc",
810
+ ) -> SyncOrAsync[AuthenticationFactorsListResource]:
811
+ """Lists the Auth Factors for a user.
812
+
813
+ Kwargs:
814
+ user_id (str): The unique ID of the User to list the auth factors for.
815
+ limit (int): Maximum number of records to return. (Optional)
816
+ before (str): Pagination cursor to receive records before a provided AuthenticationFactor ID. (Optional)
817
+ after (str): Pagination cursor to receive records after a provided AuthenticationFactor ID. (Optional)
818
+ order (Literal["asc","desc"]): Sort records in either ascending or descending order by created_at timestamp.(Optional)
819
+ Returns:
820
+ AuthenticationFactorsListResource: List of Authentication Factors for a User from WorkOS.
821
+ """
822
+ ...
823
+
824
+ def get_invitation(self, invitation_id: str) -> SyncOrAsync[Invitation]:
825
+ """Get the details of an invitation.
826
+
827
+ Args:
828
+ invitation_id (str): The unique ID of the Invitation.
829
+
830
+ Returns:
831
+ Invitation: Invitation response from WorkOS.
832
+ """
833
+ ...
834
+
835
+ def find_invitation_by_token(
836
+ self, invitation_token: str
837
+ ) -> SyncOrAsync[Invitation]:
838
+ """Get the details of an invitation.
839
+
840
+ Args:
841
+ invitation_token (str): The token of the Invitation.
842
+
843
+ Returns:
844
+ Invitation: Invitation response from WorkOS.
845
+ """
846
+ ...
847
+
848
+ def list_invitations(
849
+ self,
850
+ *,
851
+ email: Optional[str] = None,
852
+ organization_id: Optional[str] = None,
853
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
854
+ before: Optional[str] = None,
855
+ after: Optional[str] = None,
856
+ order: PaginationOrder = "desc",
857
+ ) -> SyncOrAsync[InvitationsListResource]:
858
+ """Get a list of all of your existing invitations matching the criteria specified.
859
+
860
+ Kwargs:
861
+ email (str): Filter Invitations by email. (Optional)
862
+ organization_id (str): Filter Invitations by organization. (Optional)
863
+ limit (int): Maximum number of records to return. (Optional)
864
+ before (str): Pagination cursor to receive records before a provided Invitation ID. (Optional)
865
+ after (str): Pagination cursor to receive records after a provided Invitation ID. (Optional)
866
+ order (Literal["asc","desc"]): Sort records in either ascending or descending order by created_at timestamp. (Optional)
867
+
868
+ Returns:
869
+ InvitationsListResource: Invitations list response from WorkOS.
870
+ """
871
+ ...
872
+
873
+ def send_invitation(
874
+ self,
875
+ *,
876
+ email: str,
877
+ organization_id: Optional[str] = None,
878
+ expires_in_days: Optional[int] = None,
879
+ inviter_user_id: Optional[str] = None,
880
+ role_slug: Optional[str] = None,
881
+ ) -> SyncOrAsync[Invitation]:
882
+ """Sends an Invitation to a recipient.
883
+
884
+ Kwargs:
885
+ email: The email address of the recipient.
886
+ organization_id: The ID of the Organization to which the recipient is being invited. (Optional)
887
+ expires_in_days: The number of days the invitations will be valid for. Must be between 1 and 30, defaults to 7 if not specified. (Optional)
888
+ inviter_user_id: The ID of the User sending the invitation. (Optional)
889
+ role_slug: The unique slug of the Role to give the Membership once the invite is accepted (Optional)
890
+
891
+ Returns:
892
+ Invitation: Sent Invitation response from WorkOS.
893
+ """
894
+ ...
895
+
896
+ def revoke_invitation(self, invitation_id: str) -> SyncOrAsync[Invitation]:
897
+ """Revokes an existing Invitation.
898
+
899
+ Args:
900
+ invitation_id (str): The unique ID of the Invitation.
901
+
902
+ Returns:
903
+ Invitation: Invitation response from WorkOS.
904
+ """
905
+ ...
906
+
907
+ def resend_invitation(self, invitation_id: str) -> SyncOrAsync[Invitation]:
908
+ """Resends an existing Invitation.
909
+
910
+ Args:
911
+ invitation_id (str): The unique ID of the Invitation.
912
+
913
+ Returns:
914
+ Invitation: Invitation response from WorkOS.
915
+ """
916
+ ...
917
+
918
+ def list_feature_flags(
919
+ self,
920
+ user_id: str,
921
+ *,
922
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
923
+ before: Optional[str] = None,
924
+ after: Optional[str] = None,
925
+ order: PaginationOrder = "desc",
926
+ ) -> SyncOrAsync[FeatureFlagsListResource]:
927
+ """Retrieve a list of feature flags for a user
928
+
929
+ Args:
930
+ user_id (str): User's unique identifier
931
+ limit (int): Maximum number of records to return. (Optional)
932
+ before (str): Pagination cursor to receive records before a provided Feature Flag ID. (Optional)
933
+ after (str): Pagination cursor to receive records after a provided Feature Flag ID. (Optional)
934
+ order (Literal["asc","desc"]): Sort records in either ascending or descending (default) order by created_at timestamp. (Optional)
935
+
936
+ Returns:
937
+ FeatureFlagsListResource: Feature flags list response from WorkOS.
938
+ """
939
+ ...
940
+
941
+
942
+ class UserManagement(UserManagementModule):
943
+ _http_client: SyncHTTPClient
944
+
945
+ def __init__(
946
+ self, http_client: SyncHTTPClient, client_configuration: ClientConfiguration
947
+ ):
948
+ self._client_configuration = client_configuration
949
+ self._http_client = http_client
950
+
951
+ def load_sealed_session(
952
+ self, *, sealed_session: str, cookie_password: str
953
+ ) -> Session:
954
+ return Session(
955
+ user_management=self,
956
+ client_id=self._http_client.client_id,
957
+ session_data=sealed_session,
958
+ cookie_password=cookie_password,
959
+ )
960
+
961
+ def get_user(self, user_id: str) -> User:
962
+ response = self._http_client.request(
963
+ USER_DETAIL_PATH.format(user_id), method=REQUEST_METHOD_GET
964
+ )
965
+
966
+ return User.model_validate(response)
967
+
968
+ def get_user_by_external_id(self, external_id: str) -> User:
969
+ response = self._http_client.request(
970
+ USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id),
971
+ method=REQUEST_METHOD_GET,
972
+ )
973
+
974
+ return User.model_validate(response)
975
+
976
+ def list_users(
977
+ self,
978
+ *,
979
+ email: Optional[str] = None,
980
+ organization_id: Optional[str] = None,
981
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
982
+ before: Optional[str] = None,
983
+ after: Optional[str] = None,
984
+ order: PaginationOrder = "desc",
985
+ ) -> UsersListResource:
986
+ params: UsersListFilters = {
987
+ "email": email,
988
+ "organization_id": organization_id,
989
+ "limit": limit,
990
+ "before": before,
991
+ "after": after,
992
+ "order": order,
993
+ }
994
+
995
+ response = self._http_client.request(
996
+ USER_PATH, method=REQUEST_METHOD_GET, params=params
997
+ )
998
+
999
+ return UsersListResource(
1000
+ list_method=self.list_users,
1001
+ list_args=params,
1002
+ **ListPage[User](**response).model_dump(),
1003
+ )
1004
+
1005
+ def create_user(
1006
+ self,
1007
+ *,
1008
+ email: str,
1009
+ password: Optional[str] = None,
1010
+ password_hash: Optional[str] = None,
1011
+ password_hash_type: Optional[PasswordHashType] = None,
1012
+ first_name: Optional[str] = None,
1013
+ last_name: Optional[str] = None,
1014
+ email_verified: Optional[bool] = None,
1015
+ external_id: Optional[str] = None,
1016
+ metadata: Optional[Metadata] = None,
1017
+ ) -> User:
1018
+ json = {
1019
+ "email": email,
1020
+ "password": password,
1021
+ "password_hash": password_hash,
1022
+ "password_hash_type": password_hash_type,
1023
+ "first_name": first_name,
1024
+ "last_name": last_name,
1025
+ "email_verified": email_verified or False,
1026
+ "external_id": external_id,
1027
+ "metadata": metadata,
1028
+ }
1029
+
1030
+ response = self._http_client.request(
1031
+ USER_PATH, method=REQUEST_METHOD_POST, json=json
1032
+ )
1033
+
1034
+ return User.model_validate(response)
1035
+
1036
+ def update_user(
1037
+ self,
1038
+ *,
1039
+ user_id: str,
1040
+ first_name: Optional[str] = None,
1041
+ last_name: Optional[str] = None,
1042
+ email: Optional[str] = None,
1043
+ email_verified: Optional[bool] = None,
1044
+ password: Optional[str] = None,
1045
+ password_hash: Optional[str] = None,
1046
+ password_hash_type: Optional[PasswordHashType] = None,
1047
+ external_id: Optional[str] = None,
1048
+ metadata: Optional[Metadata] = None,
1049
+ locale: Optional[str] = None,
1050
+ ) -> User:
1051
+ json = {
1052
+ "first_name": first_name,
1053
+ "last_name": last_name,
1054
+ "email": email,
1055
+ "email_verified": email_verified,
1056
+ "password": password,
1057
+ "password_hash": password_hash,
1058
+ "password_hash_type": password_hash_type,
1059
+ "external_id": external_id,
1060
+ "metadata": metadata,
1061
+ "locale": locale,
1062
+ }
1063
+
1064
+ response = self._http_client.request(
1065
+ USER_DETAIL_PATH.format(user_id), method=REQUEST_METHOD_PUT, json=json
1066
+ )
1067
+
1068
+ return User.model_validate(response)
1069
+
1070
+ def delete_user(self, user_id: str) -> None:
1071
+ self._http_client.request(
1072
+ USER_DETAIL_PATH.format(user_id),
1073
+ method=REQUEST_METHOD_DELETE,
1074
+ )
1075
+
1076
+ def create_organization_membership(
1077
+ self,
1078
+ *,
1079
+ user_id: str,
1080
+ organization_id: str,
1081
+ role_slug: Optional[str] = None,
1082
+ role_slugs: Optional[Sequence[str]] = None,
1083
+ ) -> OrganizationMembership:
1084
+ json = {
1085
+ "user_id": user_id,
1086
+ "organization_id": organization_id,
1087
+ "role_slug": role_slug,
1088
+ "role_slugs": role_slugs,
1089
+ }
1090
+
1091
+ response = self._http_client.request(
1092
+ ORGANIZATION_MEMBERSHIP_PATH, method=REQUEST_METHOD_POST, json=json
1093
+ )
1094
+
1095
+ return OrganizationMembership.model_validate(response)
1096
+
1097
+ def update_organization_membership(
1098
+ self,
1099
+ *,
1100
+ organization_membership_id: str,
1101
+ role_slug: Optional[str] = None,
1102
+ role_slugs: Optional[Sequence[str]] = None,
1103
+ ) -> OrganizationMembership:
1104
+ json = {
1105
+ "role_slug": role_slug,
1106
+ "role_slugs": role_slugs,
1107
+ }
1108
+
1109
+ response = self._http_client.request(
1110
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1111
+ method=REQUEST_METHOD_PUT,
1112
+ json=json,
1113
+ )
1114
+
1115
+ return OrganizationMembership.model_validate(response)
1116
+
1117
+ def get_organization_membership(
1118
+ self, organization_membership_id: str
1119
+ ) -> OrganizationMembership:
1120
+ response = self._http_client.request(
1121
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1122
+ method=REQUEST_METHOD_GET,
1123
+ )
1124
+
1125
+ return OrganizationMembership.model_validate(response)
1126
+
1127
+ def list_organization_memberships(
1128
+ self,
1129
+ *,
1130
+ user_id: Optional[str] = None,
1131
+ organization_id: Optional[str] = None,
1132
+ statuses: Optional[Sequence[OrganizationMembershipStatus]] = None,
1133
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1134
+ before: Optional[str] = None,
1135
+ after: Optional[str] = None,
1136
+ order: PaginationOrder = "desc",
1137
+ ) -> OrganizationMembershipsListResource:
1138
+ params: OrganizationMembershipsListFilters = {
1139
+ "user_id": user_id,
1140
+ "organization_id": organization_id,
1141
+ "statuses": statuses,
1142
+ "limit": limit,
1143
+ "before": before,
1144
+ "after": after,
1145
+ "order": order,
1146
+ }
1147
+
1148
+ response = self._http_client.request(
1149
+ ORGANIZATION_MEMBERSHIP_PATH, method=REQUEST_METHOD_GET, params=params
1150
+ )
1151
+
1152
+ return OrganizationMembershipsListResource(
1153
+ list_method=self.list_organization_memberships,
1154
+ list_args=params,
1155
+ **ListPage[OrganizationMembership](**response).model_dump(),
1156
+ )
1157
+
1158
+ def delete_organization_membership(self, organization_membership_id: str) -> None:
1159
+ self._http_client.request(
1160
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1161
+ method=REQUEST_METHOD_DELETE,
1162
+ )
1163
+
1164
+ def deactivate_organization_membership(
1165
+ self, organization_membership_id: str
1166
+ ) -> OrganizationMembership:
1167
+ response = self._http_client.request(
1168
+ ORGANIZATION_MEMBERSHIP_DEACTIVATE_PATH.format(organization_membership_id),
1169
+ method=REQUEST_METHOD_PUT,
1170
+ )
1171
+
1172
+ return OrganizationMembership.model_validate(response)
1173
+
1174
+ def reactivate_organization_membership(
1175
+ self, organization_membership_id: str
1176
+ ) -> OrganizationMembership:
1177
+ response = self._http_client.request(
1178
+ ORGANIZATION_MEMBERSHIP_REACTIVATE_PATH.format(organization_membership_id),
1179
+ method=REQUEST_METHOD_PUT,
1180
+ )
1181
+
1182
+ return OrganizationMembership.model_validate(response)
1183
+
1184
+ def _authenticate_with(
1185
+ self,
1186
+ payload: AuthenticateWithParameters,
1187
+ response_model: Type[AuthenticationResponseType],
1188
+ ) -> AuthenticationResponseType:
1189
+ json = {
1190
+ "client_id": self._http_client.client_id,
1191
+ "client_secret": self._http_client.api_key,
1192
+ **payload,
1193
+ }
1194
+
1195
+ response = self._http_client.request(
1196
+ USER_AUTHENTICATE_PATH,
1197
+ method=REQUEST_METHOD_POST,
1198
+ json=json,
1199
+ )
1200
+
1201
+ response_data = dict(response)
1202
+
1203
+ session = cast(Optional[SessionConfig], payload.get("session", None))
1204
+
1205
+ if session is not None and session.get("seal_session") is True:
1206
+ response_data["sealed_session"] = Session.seal_data(
1207
+ response_data, str(session.get("cookie_password"))
1208
+ )
1209
+
1210
+ return response_model.model_validate(response_data)
1211
+
1212
+ def authenticate_with_password(
1213
+ self,
1214
+ *,
1215
+ email: str,
1216
+ password: str,
1217
+ ip_address: Optional[str] = None,
1218
+ user_agent: Optional[str] = None,
1219
+ ) -> AuthenticationResponse:
1220
+ payload: AuthenticateWithPasswordParameters = {
1221
+ "email": email,
1222
+ "password": password,
1223
+ "grant_type": "password",
1224
+ "ip_address": ip_address,
1225
+ "user_agent": user_agent,
1226
+ }
1227
+
1228
+ return self._authenticate_with(payload, response_model=AuthenticationResponse)
1229
+
1230
+ def authenticate_with_code(
1231
+ self,
1232
+ *,
1233
+ code: str,
1234
+ session: Optional[SessionConfig] = None,
1235
+ code_verifier: Optional[str] = None,
1236
+ ip_address: Optional[str] = None,
1237
+ user_agent: Optional[str] = None,
1238
+ invitation_token: Optional[str] = None,
1239
+ ) -> AuthKitAuthenticationResponse:
1240
+ if (
1241
+ session is not None
1242
+ and session.get("seal_session")
1243
+ and not session.get("cookie_password")
1244
+ ):
1245
+ raise ValueError("cookie_password is required when sealing session")
1246
+
1247
+ payload: AuthenticateWithCodeParameters = {
1248
+ "code": code,
1249
+ "grant_type": "authorization_code",
1250
+ "ip_address": ip_address,
1251
+ "user_agent": user_agent,
1252
+ "code_verifier": code_verifier,
1253
+ "session": session,
1254
+ "invitation_token": invitation_token,
1255
+ }
1256
+
1257
+ return self._authenticate_with(
1258
+ payload, response_model=AuthKitAuthenticationResponse
1259
+ )
1260
+
1261
+ def authenticate_with_magic_auth(
1262
+ self,
1263
+ *,
1264
+ code: str,
1265
+ email: str,
1266
+ link_authorization_code: Optional[str] = None,
1267
+ ip_address: Optional[str] = None,
1268
+ user_agent: Optional[str] = None,
1269
+ ) -> AuthenticationResponse:
1270
+ payload: AuthenticateWithMagicAuthParameters = {
1271
+ "code": code,
1272
+ "email": email,
1273
+ "grant_type": "urn:workos:oauth:grant-type:magic-auth:code",
1274
+ "link_authorization_code": link_authorization_code,
1275
+ "ip_address": ip_address,
1276
+ "user_agent": user_agent,
1277
+ }
1278
+
1279
+ return self._authenticate_with(payload, response_model=AuthenticationResponse)
1280
+
1281
+ def authenticate_with_email_verification(
1282
+ self,
1283
+ *,
1284
+ code: str,
1285
+ pending_authentication_token: str,
1286
+ ip_address: Optional[str] = None,
1287
+ user_agent: Optional[str] = None,
1288
+ ) -> AuthenticationResponse:
1289
+ payload: AuthenticateWithEmailVerificationParameters = {
1290
+ "code": code,
1291
+ "pending_authentication_token": pending_authentication_token,
1292
+ "grant_type": "urn:workos:oauth:grant-type:email-verification:code",
1293
+ "ip_address": ip_address,
1294
+ "user_agent": user_agent,
1295
+ }
1296
+
1297
+ return self._authenticate_with(payload, response_model=AuthenticationResponse)
1298
+
1299
+ def authenticate_with_totp(
1300
+ self,
1301
+ *,
1302
+ code: str,
1303
+ authentication_challenge_id: str,
1304
+ pending_authentication_token: str,
1305
+ ip_address: Optional[str] = None,
1306
+ user_agent: Optional[str] = None,
1307
+ ) -> AuthenticationResponse:
1308
+ payload: AuthenticateWithTotpParameters = {
1309
+ "code": code,
1310
+ "authentication_challenge_id": authentication_challenge_id,
1311
+ "pending_authentication_token": pending_authentication_token,
1312
+ "grant_type": "urn:workos:oauth:grant-type:mfa-totp",
1313
+ "ip_address": ip_address,
1314
+ "user_agent": user_agent,
1315
+ }
1316
+
1317
+ return self._authenticate_with(payload, response_model=AuthenticationResponse)
1318
+
1319
+ def authenticate_with_organization_selection(
1320
+ self,
1321
+ *,
1322
+ organization_id: str,
1323
+ pending_authentication_token: str,
1324
+ ip_address: Optional[str] = None,
1325
+ user_agent: Optional[str] = None,
1326
+ ) -> AuthenticationResponse:
1327
+ payload: AuthenticateWithOrganizationSelectionParameters = {
1328
+ "organization_id": organization_id,
1329
+ "pending_authentication_token": pending_authentication_token,
1330
+ "grant_type": "urn:workos:oauth:grant-type:organization-selection",
1331
+ "ip_address": ip_address,
1332
+ "user_agent": user_agent,
1333
+ }
1334
+
1335
+ return self._authenticate_with(payload, response_model=AuthenticationResponse)
1336
+
1337
+ def authenticate_with_refresh_token(
1338
+ self,
1339
+ *,
1340
+ refresh_token: str,
1341
+ session: Optional[SessionConfig] = None,
1342
+ organization_id: Optional[str] = None,
1343
+ ip_address: Optional[str] = None,
1344
+ user_agent: Optional[str] = None,
1345
+ ) -> RefreshTokenAuthenticationResponse:
1346
+ if (
1347
+ session is not None
1348
+ and session.get("seal_session")
1349
+ and not session.get("cookie_password")
1350
+ ):
1351
+ raise ValueError("cookie_password is required when sealing session")
1352
+
1353
+ payload: AuthenticateWithRefreshTokenParameters = {
1354
+ "refresh_token": refresh_token,
1355
+ "organization_id": organization_id,
1356
+ "grant_type": "refresh_token",
1357
+ "ip_address": ip_address,
1358
+ "user_agent": user_agent,
1359
+ "session": session,
1360
+ }
1361
+
1362
+ return self._authenticate_with(
1363
+ payload, response_model=RefreshTokenAuthenticationResponse
1364
+ )
1365
+
1366
+ def get_password_reset(self, password_reset_id: str) -> PasswordReset:
1367
+ response = self._http_client.request(
1368
+ PASSWORD_RESET_DETAIL_PATH.format(password_reset_id),
1369
+ method=REQUEST_METHOD_GET,
1370
+ )
1371
+
1372
+ return PasswordReset.model_validate(response)
1373
+
1374
+ def create_password_reset(self, email: str) -> PasswordReset:
1375
+ json = {
1376
+ "email": email,
1377
+ }
1378
+
1379
+ response = self._http_client.request(
1380
+ PASSWORD_RESET_PATH, method=REQUEST_METHOD_POST, json=json
1381
+ )
1382
+
1383
+ return PasswordReset.model_validate(response)
1384
+
1385
+ def reset_password(self, *, token: str, new_password: str) -> User:
1386
+ json = {
1387
+ "token": token,
1388
+ "new_password": new_password,
1389
+ }
1390
+
1391
+ response = self._http_client.request(
1392
+ USER_RESET_PASSWORD_PATH, method=REQUEST_METHOD_POST, json=json
1393
+ )
1394
+
1395
+ return User.model_validate(response["user"])
1396
+
1397
+ def get_email_verification(self, email_verification_id: str) -> EmailVerification:
1398
+ response = self._http_client.request(
1399
+ EMAIL_VERIFICATION_DETAIL_PATH.format(email_verification_id),
1400
+ method=REQUEST_METHOD_GET,
1401
+ )
1402
+
1403
+ return EmailVerification.model_validate(response)
1404
+
1405
+ def send_verification_email(self, user_id: str) -> User:
1406
+ response = self._http_client.request(
1407
+ USER_SEND_VERIFICATION_EMAIL_PATH.format(user_id),
1408
+ method=REQUEST_METHOD_POST,
1409
+ )
1410
+
1411
+ return User.model_validate(response["user"])
1412
+
1413
+ def verify_email(self, *, user_id: str, code: str) -> User:
1414
+ json = {
1415
+ "code": code,
1416
+ }
1417
+
1418
+ response = self._http_client.request(
1419
+ USER_VERIFY_EMAIL_CODE_PATH.format(user_id),
1420
+ method=REQUEST_METHOD_POST,
1421
+ json=json,
1422
+ )
1423
+
1424
+ return User.model_validate(response["user"])
1425
+
1426
+ def get_magic_auth(self, magic_auth_id: str) -> MagicAuth:
1427
+ response = self._http_client.request(
1428
+ MAGIC_AUTH_DETAIL_PATH.format(magic_auth_id), method=REQUEST_METHOD_GET
1429
+ )
1430
+
1431
+ return MagicAuth.model_validate(response)
1432
+
1433
+ def create_magic_auth(
1434
+ self, *, email: str, invitation_token: Optional[str] = None
1435
+ ) -> MagicAuth:
1436
+ json = {
1437
+ "email": email,
1438
+ "invitation_token": invitation_token,
1439
+ }
1440
+
1441
+ response = self._http_client.request(
1442
+ MAGIC_AUTH_PATH, method=REQUEST_METHOD_POST, json=json
1443
+ )
1444
+
1445
+ return MagicAuth.model_validate(response)
1446
+
1447
+ def list_sessions(
1448
+ self,
1449
+ *,
1450
+ user_id: str,
1451
+ limit: Optional[int] = DEFAULT_LIST_RESPONSE_LIMIT,
1452
+ before: Optional[str] = None,
1453
+ after: Optional[str] = None,
1454
+ order: Optional[PaginationOrder] = "desc",
1455
+ ) -> "SessionsListResource":
1456
+ limit_value: int = limit if limit is not None else DEFAULT_LIST_RESPONSE_LIMIT
1457
+
1458
+ params: ListArgs = {
1459
+ "limit": limit_value,
1460
+ "before": before,
1461
+ "after": after,
1462
+ "order": order,
1463
+ }
1464
+
1465
+ response = self._http_client.request(
1466
+ USER_SESSIONS_PATH.format(user_id),
1467
+ method=REQUEST_METHOD_GET,
1468
+ params=params,
1469
+ )
1470
+
1471
+ list_args: SessionsListFilters = {
1472
+ "limit": limit_value,
1473
+ "before": before,
1474
+ "after": after,
1475
+ "user_id": user_id,
1476
+ }
1477
+ if order is not None:
1478
+ list_args["order"] = order
1479
+
1480
+ return SessionsListResource(
1481
+ list_method=self.list_sessions,
1482
+ list_args=list_args,
1483
+ **ListPage[UserManagementSession](**response).model_dump(),
1484
+ )
1485
+
1486
+ def revoke_session(self, *, session_id: str) -> None:
1487
+ json = {"session_id": session_id}
1488
+
1489
+ self._http_client.request(
1490
+ SESSIONS_REVOKE_PATH, method=REQUEST_METHOD_POST, json=json
1491
+ )
1492
+
1493
+ def enroll_auth_factor(
1494
+ self,
1495
+ *,
1496
+ user_id: str,
1497
+ type: AuthenticationFactorType,
1498
+ totp_issuer: Optional[str] = None,
1499
+ totp_user: Optional[str] = None,
1500
+ totp_secret: Optional[str] = None,
1501
+ ) -> AuthenticationFactorTotpAndChallengeResponse:
1502
+ json = {
1503
+ "type": type,
1504
+ "totp_issuer": totp_issuer,
1505
+ "totp_user": totp_user,
1506
+ "totp_secret": totp_secret,
1507
+ }
1508
+
1509
+ response = self._http_client.request(
1510
+ USER_AUTH_FACTORS_PATH.format(user_id),
1511
+ method=REQUEST_METHOD_POST,
1512
+ json=json,
1513
+ )
1514
+
1515
+ return AuthenticationFactorTotpAndChallengeResponse.model_validate(response)
1516
+
1517
+ def list_auth_factors(
1518
+ self,
1519
+ *,
1520
+ user_id: str,
1521
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1522
+ before: Optional[str] = None,
1523
+ after: Optional[str] = None,
1524
+ order: PaginationOrder = "desc",
1525
+ ) -> AuthenticationFactorsListResource:
1526
+ params: ListArgs = {
1527
+ "limit": limit,
1528
+ "before": before,
1529
+ "after": after,
1530
+ "order": order,
1531
+ }
1532
+
1533
+ response = self._http_client.request(
1534
+ USER_AUTH_FACTORS_PATH.format(user_id),
1535
+ method=REQUEST_METHOD_GET,
1536
+ params=params,
1537
+ )
1538
+
1539
+ # We don't spread params on this dict to make mypy happy
1540
+ list_args: AuthenticationFactorsListFilters = {
1541
+ "limit": limit or DEFAULT_LIST_RESPONSE_LIMIT,
1542
+ "before": before,
1543
+ "after": after,
1544
+ "order": order,
1545
+ "user_id": user_id,
1546
+ }
1547
+
1548
+ return AuthenticationFactorsListResource(
1549
+ list_method=self.list_auth_factors,
1550
+ list_args=list_args,
1551
+ **ListPage[AuthenticationFactor](**response).model_dump(),
1552
+ )
1553
+
1554
+ def get_invitation(self, invitation_id: str) -> Invitation:
1555
+ response = self._http_client.request(
1556
+ INVITATION_DETAIL_PATH.format(invitation_id),
1557
+ method=REQUEST_METHOD_GET,
1558
+ )
1559
+
1560
+ return Invitation.model_validate(response)
1561
+
1562
+ def find_invitation_by_token(self, invitation_token: str) -> Invitation:
1563
+ response = self._http_client.request(
1564
+ INVITATION_DETAIL_BY_TOKEN_PATH.format(invitation_token),
1565
+ method=REQUEST_METHOD_GET,
1566
+ )
1567
+
1568
+ return Invitation.model_validate(response)
1569
+
1570
+ def list_invitations(
1571
+ self,
1572
+ *,
1573
+ email: Optional[str] = None,
1574
+ organization_id: Optional[str] = None,
1575
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1576
+ before: Optional[str] = None,
1577
+ after: Optional[str] = None,
1578
+ order: PaginationOrder = "desc",
1579
+ ) -> InvitationsListResource:
1580
+ params: InvitationsListFilters = {
1581
+ "email": email,
1582
+ "organization_id": organization_id,
1583
+ "limit": limit,
1584
+ "before": before,
1585
+ "after": after,
1586
+ "order": order,
1587
+ }
1588
+
1589
+ response = self._http_client.request(
1590
+ INVITATION_PATH, method=REQUEST_METHOD_GET, params=params
1591
+ )
1592
+
1593
+ return InvitationsListResource(
1594
+ list_method=self.list_invitations,
1595
+ list_args=params,
1596
+ **ListPage[Invitation](**response).model_dump(),
1597
+ )
1598
+
1599
+ def send_invitation(
1600
+ self,
1601
+ *,
1602
+ email: str,
1603
+ organization_id: Optional[str] = None,
1604
+ expires_in_days: Optional[int] = None,
1605
+ inviter_user_id: Optional[str] = None,
1606
+ role_slug: Optional[str] = None,
1607
+ ) -> Invitation:
1608
+ json = {
1609
+ "email": email,
1610
+ "organization_id": organization_id,
1611
+ "expires_in_days": expires_in_days,
1612
+ "inviter_user_id": inviter_user_id,
1613
+ "role_slug": role_slug,
1614
+ }
1615
+
1616
+ response = self._http_client.request(
1617
+ INVITATION_PATH, method=REQUEST_METHOD_POST, json=json
1618
+ )
1619
+
1620
+ return Invitation.model_validate(response)
1621
+
1622
+ def revoke_invitation(self, invitation_id: str) -> Invitation:
1623
+ response = self._http_client.request(
1624
+ INVITATION_REVOKE_PATH.format(invitation_id), method=REQUEST_METHOD_POST
1625
+ )
1626
+
1627
+ return Invitation.model_validate(response)
1628
+
1629
+ def resend_invitation(self, invitation_id: str) -> Invitation:
1630
+ response = self._http_client.request(
1631
+ INVITATION_RESEND_PATH.format(invitation_id), method=REQUEST_METHOD_POST
1632
+ )
1633
+
1634
+ return Invitation.model_validate(response)
1635
+
1636
+ def list_feature_flags(
1637
+ self,
1638
+ user_id: str,
1639
+ *,
1640
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1641
+ before: Optional[str] = None,
1642
+ after: Optional[str] = None,
1643
+ order: PaginationOrder = "desc",
1644
+ ) -> FeatureFlagsListResource:
1645
+ list_params: FeatureFlagListFilters = {
1646
+ "limit": limit,
1647
+ "before": before,
1648
+ "after": after,
1649
+ "order": order,
1650
+ }
1651
+
1652
+ response = self._http_client.request(
1653
+ USER_FEATURE_FLAGS_PATH.format(user_id),
1654
+ method=REQUEST_METHOD_GET,
1655
+ params=list_params,
1656
+ )
1657
+
1658
+ return FeatureFlagsListResource(
1659
+ list_method=self.list_feature_flags,
1660
+ list_args=list_params,
1661
+ **ListPage[FeatureFlag](**response).model_dump(),
1662
+ )
1663
+
1664
+
1665
+ class AsyncUserManagement(UserManagementModule):
1666
+ _http_client: AsyncHTTPClient
1667
+
1668
+ def __init__(
1669
+ self, http_client: AsyncHTTPClient, client_configuration: ClientConfiguration
1670
+ ):
1671
+ self._client_configuration = client_configuration
1672
+ self._http_client = http_client
1673
+
1674
+ async def load_sealed_session(
1675
+ self, *, sealed_session: str, cookie_password: str
1676
+ ) -> AsyncSession:
1677
+ return AsyncSession(
1678
+ user_management=self,
1679
+ client_id=self._http_client.client_id,
1680
+ session_data=sealed_session,
1681
+ cookie_password=cookie_password,
1682
+ )
1683
+
1684
+ async def get_user(self, user_id: str) -> User:
1685
+ response = await self._http_client.request(
1686
+ USER_DETAIL_PATH.format(user_id), method=REQUEST_METHOD_GET
1687
+ )
1688
+
1689
+ return User.model_validate(response)
1690
+
1691
+ async def get_user_by_external_id(self, external_id: str) -> User:
1692
+ response = await self._http_client.request(
1693
+ USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id),
1694
+ method=REQUEST_METHOD_GET,
1695
+ )
1696
+
1697
+ return User.model_validate(response)
1698
+
1699
+ async def list_users(
1700
+ self,
1701
+ *,
1702
+ email: Optional[str] = None,
1703
+ organization_id: Optional[str] = None,
1704
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1705
+ before: Optional[str] = None,
1706
+ after: Optional[str] = None,
1707
+ order: PaginationOrder = "desc",
1708
+ ) -> UsersListResource:
1709
+ params: UsersListFilters = {
1710
+ "email": email,
1711
+ "organization_id": organization_id,
1712
+ "limit": limit,
1713
+ "before": before,
1714
+ "after": after,
1715
+ "order": order,
1716
+ }
1717
+
1718
+ response = await self._http_client.request(
1719
+ USER_PATH, method=REQUEST_METHOD_GET, params=params
1720
+ )
1721
+
1722
+ return UsersListResource(
1723
+ list_method=self.list_users,
1724
+ list_args=params,
1725
+ **ListPage[User](**response).model_dump(),
1726
+ )
1727
+
1728
+ async def create_user(
1729
+ self,
1730
+ *,
1731
+ email: str,
1732
+ password: Optional[str] = None,
1733
+ password_hash: Optional[str] = None,
1734
+ password_hash_type: Optional[PasswordHashType] = None,
1735
+ first_name: Optional[str] = None,
1736
+ last_name: Optional[str] = None,
1737
+ email_verified: Optional[bool] = None,
1738
+ external_id: Optional[str] = None,
1739
+ metadata: Optional[Metadata] = None,
1740
+ ) -> User:
1741
+ json = {
1742
+ "email": email,
1743
+ "password": password,
1744
+ "password_hash": password_hash,
1745
+ "password_hash_type": password_hash_type,
1746
+ "first_name": first_name,
1747
+ "last_name": last_name,
1748
+ "email_verified": email_verified or False,
1749
+ "external_id": external_id,
1750
+ "metadata": metadata,
1751
+ }
1752
+
1753
+ response = await self._http_client.request(
1754
+ USER_PATH, method=REQUEST_METHOD_POST, json=json
1755
+ )
1756
+
1757
+ return User.model_validate(response)
1758
+
1759
+ async def update_user(
1760
+ self,
1761
+ *,
1762
+ user_id: str,
1763
+ first_name: Optional[str] = None,
1764
+ last_name: Optional[str] = None,
1765
+ email: Optional[str] = None,
1766
+ email_verified: Optional[bool] = None,
1767
+ password: Optional[str] = None,
1768
+ password_hash: Optional[str] = None,
1769
+ password_hash_type: Optional[PasswordHashType] = None,
1770
+ external_id: Optional[str] = None,
1771
+ metadata: Optional[Metadata] = None,
1772
+ locale: Optional[str] = None,
1773
+ ) -> User:
1774
+ json = {
1775
+ "first_name": first_name,
1776
+ "last_name": last_name,
1777
+ "email": email,
1778
+ "email_verified": email_verified,
1779
+ "password": password,
1780
+ "password_hash": password_hash,
1781
+ "password_hash_type": password_hash_type,
1782
+ "external_id": external_id,
1783
+ "metadata": metadata,
1784
+ "locale": locale,
1785
+ }
1786
+
1787
+ response = await self._http_client.request(
1788
+ USER_DETAIL_PATH.format(user_id), method=REQUEST_METHOD_PUT, json=json
1789
+ )
1790
+
1791
+ return User.model_validate(response)
1792
+
1793
+ async def delete_user(self, user_id: str) -> None:
1794
+ await self._http_client.request(
1795
+ USER_DETAIL_PATH.format(user_id), method=REQUEST_METHOD_DELETE
1796
+ )
1797
+
1798
+ async def create_organization_membership(
1799
+ self,
1800
+ *,
1801
+ user_id: str,
1802
+ organization_id: str,
1803
+ role_slug: Optional[str] = None,
1804
+ role_slugs: Optional[Sequence[str]] = None,
1805
+ ) -> OrganizationMembership:
1806
+ json = {
1807
+ "user_id": user_id,
1808
+ "organization_id": organization_id,
1809
+ "role_slug": role_slug,
1810
+ "role_slugs": role_slugs,
1811
+ }
1812
+
1813
+ response = await self._http_client.request(
1814
+ ORGANIZATION_MEMBERSHIP_PATH, method=REQUEST_METHOD_POST, json=json
1815
+ )
1816
+
1817
+ return OrganizationMembership.model_validate(response)
1818
+
1819
+ async def update_organization_membership(
1820
+ self,
1821
+ *,
1822
+ organization_membership_id: str,
1823
+ role_slug: Optional[str] = None,
1824
+ role_slugs: Optional[Sequence[str]] = None,
1825
+ ) -> OrganizationMembership:
1826
+ json = {
1827
+ "role_slug": role_slug,
1828
+ "role_slugs": role_slugs,
1829
+ }
1830
+
1831
+ response = await self._http_client.request(
1832
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1833
+ method=REQUEST_METHOD_PUT,
1834
+ json=json,
1835
+ )
1836
+
1837
+ return OrganizationMembership.model_validate(response)
1838
+
1839
+ async def get_organization_membership(
1840
+ self, organization_membership_id: str
1841
+ ) -> OrganizationMembership:
1842
+ response = await self._http_client.request(
1843
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1844
+ method=REQUEST_METHOD_GET,
1845
+ )
1846
+
1847
+ return OrganizationMembership.model_validate(response)
1848
+
1849
+ async def list_organization_memberships(
1850
+ self,
1851
+ *,
1852
+ user_id: Optional[str] = None,
1853
+ organization_id: Optional[str] = None,
1854
+ statuses: Optional[Sequence[OrganizationMembershipStatus]] = None,
1855
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
1856
+ before: Optional[str] = None,
1857
+ after: Optional[str] = None,
1858
+ order: PaginationOrder = "desc",
1859
+ ) -> OrganizationMembershipsListResource:
1860
+ params: OrganizationMembershipsListFilters = {
1861
+ "user_id": user_id,
1862
+ "organization_id": organization_id,
1863
+ "statuses": statuses,
1864
+ "limit": limit,
1865
+ "before": before,
1866
+ "after": after,
1867
+ "order": order,
1868
+ }
1869
+
1870
+ response = await self._http_client.request(
1871
+ ORGANIZATION_MEMBERSHIP_PATH, method=REQUEST_METHOD_GET, params=params
1872
+ )
1873
+
1874
+ return OrganizationMembershipsListResource(
1875
+ list_method=self.list_organization_memberships,
1876
+ list_args=params,
1877
+ **ListPage[OrganizationMembership](**response).model_dump(),
1878
+ )
1879
+
1880
+ async def delete_organization_membership(
1881
+ self, organization_membership_id: str
1882
+ ) -> None:
1883
+ await self._http_client.request(
1884
+ ORGANIZATION_MEMBERSHIP_DETAIL_PATH.format(organization_membership_id),
1885
+ method=REQUEST_METHOD_DELETE,
1886
+ )
1887
+
1888
+ async def deactivate_organization_membership(
1889
+ self, organization_membership_id: str
1890
+ ) -> OrganizationMembership:
1891
+ response = await self._http_client.request(
1892
+ ORGANIZATION_MEMBERSHIP_DEACTIVATE_PATH.format(organization_membership_id),
1893
+ method=REQUEST_METHOD_PUT,
1894
+ )
1895
+
1896
+ return OrganizationMembership.model_validate(response)
1897
+
1898
+ async def reactivate_organization_membership(
1899
+ self, organization_membership_id: str
1900
+ ) -> OrganizationMembership:
1901
+ response = await self._http_client.request(
1902
+ ORGANIZATION_MEMBERSHIP_REACTIVATE_PATH.format(organization_membership_id),
1903
+ method=REQUEST_METHOD_PUT,
1904
+ )
1905
+
1906
+ return OrganizationMembership.model_validate(response)
1907
+
1908
+ async def _authenticate_with(
1909
+ self,
1910
+ payload: AuthenticateWithParameters,
1911
+ response_model: Type[AuthenticationResponseType],
1912
+ ) -> AuthenticationResponseType:
1913
+ json = {
1914
+ "client_id": self._http_client.client_id,
1915
+ "client_secret": self._http_client.api_key,
1916
+ **payload,
1917
+ }
1918
+
1919
+ response = await self._http_client.request(
1920
+ USER_AUTHENTICATE_PATH,
1921
+ method=REQUEST_METHOD_POST,
1922
+ json=json,
1923
+ )
1924
+
1925
+ response_data = dict(response)
1926
+
1927
+ session = cast(Optional[SessionConfig], payload.get("session", None))
1928
+
1929
+ if session is not None and session.get("seal_session") is True:
1930
+ response_data["sealed_session"] = Session.seal_data(
1931
+ response_data, str(session.get("cookie_password"))
1932
+ )
1933
+
1934
+ return response_model.model_validate(response_data)
1935
+
1936
+ async def authenticate_with_password(
1937
+ self,
1938
+ *,
1939
+ email: str,
1940
+ password: str,
1941
+ ip_address: Optional[str] = None,
1942
+ user_agent: Optional[str] = None,
1943
+ ) -> AuthenticationResponse:
1944
+ payload: AuthenticateWithPasswordParameters = {
1945
+ "email": email,
1946
+ "password": password,
1947
+ "grant_type": "password",
1948
+ "ip_address": ip_address,
1949
+ "user_agent": user_agent,
1950
+ }
1951
+
1952
+ return await self._authenticate_with(
1953
+ payload, response_model=AuthenticationResponse
1954
+ )
1955
+
1956
+ async def authenticate_with_code(
1957
+ self,
1958
+ *,
1959
+ code: str,
1960
+ session: Optional[SessionConfig] = None,
1961
+ code_verifier: Optional[str] = None,
1962
+ ip_address: Optional[str] = None,
1963
+ user_agent: Optional[str] = None,
1964
+ invitation_token: Optional[str] = None,
1965
+ ) -> AuthKitAuthenticationResponse:
1966
+ if (
1967
+ session is not None
1968
+ and session.get("seal_session")
1969
+ and not session.get("cookie_password")
1970
+ ):
1971
+ raise ValueError("cookie_password is required when sealing session")
1972
+
1973
+ payload: AuthenticateWithCodeParameters = {
1974
+ "code": code,
1975
+ "grant_type": "authorization_code",
1976
+ "ip_address": ip_address,
1977
+ "user_agent": user_agent,
1978
+ "code_verifier": code_verifier,
1979
+ "session": session,
1980
+ "invitation_token": invitation_token,
1981
+ }
1982
+
1983
+ return await self._authenticate_with(
1984
+ payload, response_model=AuthKitAuthenticationResponse
1985
+ )
1986
+
1987
+ async def authenticate_with_magic_auth(
1988
+ self,
1989
+ *,
1990
+ code: str,
1991
+ email: str,
1992
+ link_authorization_code: Optional[str] = None,
1993
+ ip_address: Optional[str] = None,
1994
+ user_agent: Optional[str] = None,
1995
+ ) -> AuthenticationResponse:
1996
+ payload: AuthenticateWithMagicAuthParameters = {
1997
+ "code": code,
1998
+ "email": email,
1999
+ "grant_type": "urn:workos:oauth:grant-type:magic-auth:code",
2000
+ "link_authorization_code": link_authorization_code,
2001
+ "ip_address": ip_address,
2002
+ "user_agent": user_agent,
2003
+ }
2004
+
2005
+ return await self._authenticate_with(
2006
+ payload, response_model=AuthenticationResponse
2007
+ )
2008
+
2009
+ async def authenticate_with_email_verification(
2010
+ self,
2011
+ *,
2012
+ code: str,
2013
+ pending_authentication_token: str,
2014
+ ip_address: Optional[str] = None,
2015
+ user_agent: Optional[str] = None,
2016
+ ) -> AuthenticationResponse:
2017
+ payload: AuthenticateWithEmailVerificationParameters = {
2018
+ "code": code,
2019
+ "pending_authentication_token": pending_authentication_token,
2020
+ "grant_type": "urn:workos:oauth:grant-type:email-verification:code",
2021
+ "ip_address": ip_address,
2022
+ "user_agent": user_agent,
2023
+ }
2024
+
2025
+ return await self._authenticate_with(
2026
+ payload, response_model=AuthenticationResponse
2027
+ )
2028
+
2029
+ async def authenticate_with_totp(
2030
+ self,
2031
+ *,
2032
+ code: str,
2033
+ authentication_challenge_id: str,
2034
+ pending_authentication_token: str,
2035
+ ip_address: Optional[str] = None,
2036
+ user_agent: Optional[str] = None,
2037
+ ) -> AuthenticationResponse:
2038
+ payload: AuthenticateWithTotpParameters = {
2039
+ "code": code,
2040
+ "authentication_challenge_id": authentication_challenge_id,
2041
+ "pending_authentication_token": pending_authentication_token,
2042
+ "grant_type": "urn:workos:oauth:grant-type:mfa-totp",
2043
+ "ip_address": ip_address,
2044
+ "user_agent": user_agent,
2045
+ }
2046
+
2047
+ return await self._authenticate_with(
2048
+ payload, response_model=AuthenticationResponse
2049
+ )
2050
+
2051
+ async def authenticate_with_organization_selection(
2052
+ self,
2053
+ *,
2054
+ organization_id: str,
2055
+ pending_authentication_token: str,
2056
+ ip_address: Optional[str] = None,
2057
+ user_agent: Optional[str] = None,
2058
+ ) -> AuthenticationResponse:
2059
+ payload: AuthenticateWithOrganizationSelectionParameters = {
2060
+ "organization_id": organization_id,
2061
+ "pending_authentication_token": pending_authentication_token,
2062
+ "grant_type": "urn:workos:oauth:grant-type:organization-selection",
2063
+ "ip_address": ip_address,
2064
+ "user_agent": user_agent,
2065
+ }
2066
+
2067
+ return await self._authenticate_with(
2068
+ payload, response_model=AuthenticationResponse
2069
+ )
2070
+
2071
+ async def authenticate_with_refresh_token(
2072
+ self,
2073
+ *,
2074
+ refresh_token: str,
2075
+ session: Optional[SessionConfig] = None,
2076
+ organization_id: Optional[str] = None,
2077
+ ip_address: Optional[str] = None,
2078
+ user_agent: Optional[str] = None,
2079
+ ) -> RefreshTokenAuthenticationResponse:
2080
+ if (
2081
+ session is not None
2082
+ and session.get("seal_session")
2083
+ and not session.get("cookie_password")
2084
+ ):
2085
+ raise ValueError("cookie_password is required when sealing session")
2086
+
2087
+ payload: AuthenticateWithRefreshTokenParameters = {
2088
+ "refresh_token": refresh_token,
2089
+ "organization_id": organization_id,
2090
+ "grant_type": "refresh_token",
2091
+ "ip_address": ip_address,
2092
+ "user_agent": user_agent,
2093
+ "session": session,
2094
+ }
2095
+
2096
+ return await self._authenticate_with(
2097
+ payload, response_model=RefreshTokenAuthenticationResponse
2098
+ )
2099
+
2100
+ async def get_password_reset(self, password_reset_id: str) -> PasswordReset:
2101
+ response = await self._http_client.request(
2102
+ PASSWORD_RESET_DETAIL_PATH.format(password_reset_id),
2103
+ method=REQUEST_METHOD_GET,
2104
+ )
2105
+
2106
+ return PasswordReset.model_validate(response)
2107
+
2108
+ async def create_password_reset(self, email: str) -> PasswordReset:
2109
+ json = {
2110
+ "email": email,
2111
+ }
2112
+
2113
+ response = await self._http_client.request(
2114
+ PASSWORD_RESET_PATH, method=REQUEST_METHOD_POST, json=json
2115
+ )
2116
+
2117
+ return PasswordReset.model_validate(response)
2118
+
2119
+ async def reset_password(self, *, token: str, new_password: str) -> User:
2120
+ json = {
2121
+ "token": token,
2122
+ "new_password": new_password,
2123
+ }
2124
+
2125
+ response = await self._http_client.request(
2126
+ USER_RESET_PASSWORD_PATH, method=REQUEST_METHOD_POST, json=json
2127
+ )
2128
+
2129
+ return User.model_validate(response["user"])
2130
+
2131
+ async def get_email_verification(
2132
+ self, email_verification_id: str
2133
+ ) -> EmailVerification:
2134
+ response = await self._http_client.request(
2135
+ EMAIL_VERIFICATION_DETAIL_PATH.format(email_verification_id),
2136
+ method=REQUEST_METHOD_GET,
2137
+ )
2138
+
2139
+ return EmailVerification.model_validate(response)
2140
+
2141
+ async def send_verification_email(self, user_id: str) -> User:
2142
+ response = await self._http_client.request(
2143
+ USER_SEND_VERIFICATION_EMAIL_PATH.format(user_id),
2144
+ method=REQUEST_METHOD_POST,
2145
+ )
2146
+
2147
+ return User.model_validate(response["user"])
2148
+
2149
+ async def verify_email(self, *, user_id: str, code: str) -> User:
2150
+ json = {
2151
+ "code": code,
2152
+ }
2153
+
2154
+ response = await self._http_client.request(
2155
+ USER_VERIFY_EMAIL_CODE_PATH.format(user_id),
2156
+ method=REQUEST_METHOD_POST,
2157
+ json=json,
2158
+ )
2159
+
2160
+ return User.model_validate(response["user"])
2161
+
2162
+ async def get_magic_auth(self, magic_auth_id: str) -> MagicAuth:
2163
+ response = await self._http_client.request(
2164
+ MAGIC_AUTH_DETAIL_PATH.format(magic_auth_id), method=REQUEST_METHOD_GET
2165
+ )
2166
+
2167
+ return MagicAuth.model_validate(response)
2168
+
2169
+ async def create_magic_auth(
2170
+ self,
2171
+ *,
2172
+ email: str,
2173
+ invitation_token: Optional[str] = None,
2174
+ ) -> MagicAuth:
2175
+ json = {
2176
+ "email": email,
2177
+ "invitation_token": invitation_token,
2178
+ }
2179
+
2180
+ response = await self._http_client.request(
2181
+ MAGIC_AUTH_PATH, method=REQUEST_METHOD_POST, json=json
2182
+ )
2183
+
2184
+ return MagicAuth.model_validate(response)
2185
+
2186
+ async def list_sessions(
2187
+ self,
2188
+ *,
2189
+ user_id: str,
2190
+ limit: Optional[int] = DEFAULT_LIST_RESPONSE_LIMIT,
2191
+ before: Optional[str] = None,
2192
+ after: Optional[str] = None,
2193
+ order: Optional[PaginationOrder] = "desc",
2194
+ ) -> "SessionsListResource":
2195
+ limit_value: int = limit if limit is not None else DEFAULT_LIST_RESPONSE_LIMIT
2196
+
2197
+ params: ListArgs = {
2198
+ "limit": limit_value,
2199
+ "before": before,
2200
+ "after": after,
2201
+ "order": order,
2202
+ }
2203
+
2204
+ response = await self._http_client.request(
2205
+ USER_SESSIONS_PATH.format(user_id),
2206
+ method=REQUEST_METHOD_GET,
2207
+ params=params,
2208
+ )
2209
+
2210
+ list_args: SessionsListFilters = {
2211
+ "limit": limit_value,
2212
+ "before": before,
2213
+ "after": after,
2214
+ "user_id": user_id,
2215
+ }
2216
+ if order is not None:
2217
+ list_args["order"] = order
2218
+
2219
+ return SessionsListResource(
2220
+ list_method=self.list_sessions,
2221
+ list_args=list_args,
2222
+ **ListPage[UserManagementSession](**response).model_dump(),
2223
+ )
2224
+
2225
+ async def revoke_session(self, *, session_id: str) -> None:
2226
+ json = {"session_id": session_id}
2227
+
2228
+ await self._http_client.request(
2229
+ SESSIONS_REVOKE_PATH, method=REQUEST_METHOD_POST, json=json
2230
+ )
2231
+
2232
+ async def enroll_auth_factor(
2233
+ self,
2234
+ *,
2235
+ user_id: str,
2236
+ type: AuthenticationFactorType,
2237
+ totp_issuer: Optional[str] = None,
2238
+ totp_user: Optional[str] = None,
2239
+ totp_secret: Optional[str] = None,
2240
+ ) -> AuthenticationFactorTotpAndChallengeResponse:
2241
+ json = {
2242
+ "type": type,
2243
+ "totp_issuer": totp_issuer,
2244
+ "totp_user": totp_user,
2245
+ "totp_secret": totp_secret,
2246
+ }
2247
+
2248
+ response = await self._http_client.request(
2249
+ USER_AUTH_FACTORS_PATH.format(user_id),
2250
+ method=REQUEST_METHOD_POST,
2251
+ json=json,
2252
+ )
2253
+
2254
+ return AuthenticationFactorTotpAndChallengeResponse.model_validate(response)
2255
+
2256
+ async def list_auth_factors(
2257
+ self,
2258
+ *,
2259
+ user_id: str,
2260
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
2261
+ before: Optional[str] = None,
2262
+ after: Optional[str] = None,
2263
+ order: PaginationOrder = "desc",
2264
+ ) -> AuthenticationFactorsListResource:
2265
+ params: ListArgs = {
2266
+ "limit": limit,
2267
+ "before": before,
2268
+ "after": after,
2269
+ "order": order,
2270
+ }
2271
+
2272
+ response = await self._http_client.request(
2273
+ USER_AUTH_FACTORS_PATH.format(user_id),
2274
+ method=REQUEST_METHOD_GET,
2275
+ params=params,
2276
+ )
2277
+
2278
+ # We don't spread params on this dict to make mypy happy
2279
+ list_args: AuthenticationFactorsListFilters = {
2280
+ "limit": limit or DEFAULT_LIST_RESPONSE_LIMIT,
2281
+ "before": before,
2282
+ "after": after,
2283
+ "order": order,
2284
+ "user_id": user_id,
2285
+ }
2286
+
2287
+ return AuthenticationFactorsListResource(
2288
+ list_method=self.list_auth_factors,
2289
+ list_args=list_args,
2290
+ **ListPage[AuthenticationFactor](**response).model_dump(),
2291
+ )
2292
+
2293
+ async def get_invitation(self, invitation_id: str) -> Invitation:
2294
+ response = await self._http_client.request(
2295
+ INVITATION_DETAIL_PATH.format(invitation_id), method=REQUEST_METHOD_GET
2296
+ )
2297
+
2298
+ return Invitation.model_validate(response)
2299
+
2300
+ async def find_invitation_by_token(self, invitation_token: str) -> Invitation:
2301
+ response = await self._http_client.request(
2302
+ INVITATION_DETAIL_BY_TOKEN_PATH.format(invitation_token),
2303
+ method=REQUEST_METHOD_GET,
2304
+ )
2305
+
2306
+ return Invitation.model_validate(response)
2307
+
2308
+ async def list_invitations(
2309
+ self,
2310
+ *,
2311
+ email: Optional[str] = None,
2312
+ organization_id: Optional[str] = None,
2313
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
2314
+ before: Optional[str] = None,
2315
+ after: Optional[str] = None,
2316
+ order: PaginationOrder = "desc",
2317
+ ) -> InvitationsListResource:
2318
+ params: InvitationsListFilters = {
2319
+ "email": email,
2320
+ "organization_id": organization_id,
2321
+ "limit": limit,
2322
+ "before": before,
2323
+ "after": after,
2324
+ "order": order,
2325
+ }
2326
+
2327
+ response = await self._http_client.request(
2328
+ INVITATION_PATH, method=REQUEST_METHOD_GET, params=params
2329
+ )
2330
+
2331
+ return InvitationsListResource(
2332
+ list_method=self.list_invitations,
2333
+ list_args=params,
2334
+ **ListPage[Invitation](**response).model_dump(),
2335
+ )
2336
+
2337
+ async def send_invitation(
2338
+ self,
2339
+ *,
2340
+ email: str,
2341
+ organization_id: Optional[str] = None,
2342
+ expires_in_days: Optional[int] = None,
2343
+ inviter_user_id: Optional[str] = None,
2344
+ role_slug: Optional[str] = None,
2345
+ ) -> Invitation:
2346
+ json = {
2347
+ "email": email,
2348
+ "organization_id": organization_id,
2349
+ "expires_in_days": expires_in_days,
2350
+ "inviter_user_id": inviter_user_id,
2351
+ "role_slug": role_slug,
2352
+ }
2353
+
2354
+ response = await self._http_client.request(
2355
+ INVITATION_PATH, method=REQUEST_METHOD_POST, json=json
2356
+ )
2357
+
2358
+ return Invitation.model_validate(response)
2359
+
2360
+ async def revoke_invitation(self, invitation_id: str) -> Invitation:
2361
+ response = await self._http_client.request(
2362
+ INVITATION_REVOKE_PATH.format(invitation_id), method=REQUEST_METHOD_POST
2363
+ )
2364
+
2365
+ return Invitation.model_validate(response)
2366
+
2367
+ async def resend_invitation(self, invitation_id: str) -> Invitation:
2368
+ response = await self._http_client.request(
2369
+ INVITATION_RESEND_PATH.format(invitation_id), method=REQUEST_METHOD_POST
2370
+ )
2371
+
2372
+ return Invitation.model_validate(response)
2373
+
2374
+ async def list_feature_flags(
2375
+ self,
2376
+ user_id: str,
2377
+ *,
2378
+ limit: int = DEFAULT_LIST_RESPONSE_LIMIT,
2379
+ before: Optional[str] = None,
2380
+ after: Optional[str] = None,
2381
+ order: PaginationOrder = "desc",
2382
+ ) -> FeatureFlagsListResource:
2383
+ list_params: FeatureFlagListFilters = {
2384
+ "limit": limit,
2385
+ "before": before,
2386
+ "after": after,
2387
+ "order": order,
2388
+ }
2389
+
2390
+ response = await self._http_client.request(
2391
+ USER_FEATURE_FLAGS_PATH.format(user_id),
2392
+ method=REQUEST_METHOD_GET,
2393
+ params=list_params,
2394
+ )
2395
+
2396
+ return FeatureFlagsListResource(
2397
+ list_method=self.list_feature_flags,
2398
+ list_args=list_params,
2399
+ **ListPage[FeatureFlag](**response).model_dump(),
2400
+ )