workos 1.5.1__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.
- workos/__about__.py +1 -1
- workos/__init__.py +3 -7
- workos/_base_client.py +138 -0
- workos/_client_configuration.py +10 -0
- workos/api_keys.py +53 -0
- workos/async_client.py +144 -0
- workos/audit_logs.py +125 -0
- workos/client.py +110 -18
- workos/directory_sync.py +379 -99
- workos/events.py +111 -0
- workos/exceptions.py +53 -26
- workos/fga.py +649 -0
- workos/mfa.py +205 -0
- workos/organization_domains.py +179 -0
- workos/organizations.py +403 -73
- workos/passwordless.py +67 -43
- workos/pipes.py +93 -0
- workos/portal.py +51 -28
- workos/session.py +337 -0
- workos/sso.py +311 -101
- workos/types/__init__.py +4 -0
- workos/types/api_keys/__init__.py +1 -0
- workos/types/api_keys/api_keys.py +20 -0
- workos/types/audit_logs/__init__.py +6 -0
- workos/types/audit_logs/audit_log_event.py +16 -0
- workos/types/audit_logs/audit_log_event_actor.py +12 -0
- workos/types/audit_logs/audit_log_event_context.py +8 -0
- workos/types/audit_logs/audit_log_event_target.py +12 -0
- workos/types/audit_logs/audit_log_export.py +18 -0
- workos/types/audit_logs/audit_log_metadata.py +4 -0
- workos/types/directory_sync/__init__.py +5 -0
- workos/types/directory_sync/directory.py +31 -0
- workos/types/directory_sync/directory_group.py +16 -0
- workos/types/directory_sync/directory_state.py +28 -0
- workos/types/directory_sync/directory_type.py +24 -0
- workos/types/directory_sync/directory_user.py +50 -0
- workos/types/directory_sync/list_filters.py +21 -0
- workos/types/events/__init__.py +13 -0
- workos/types/events/authentication_payload.py +70 -0
- workos/types/events/connection_payload_with_legacy_fields.py +5 -0
- workos/types/events/directory_group_membership_payload.py +9 -0
- workos/types/events/directory_group_with_previous_attributes.py +6 -0
- workos/types/events/directory_payload.py +16 -0
- workos/types/events/directory_payload_with_legacy_fields.py +29 -0
- workos/types/events/directory_user_with_previous_attributes.py +6 -0
- workos/types/events/event.py +324 -0
- workos/types/events/event_model.py +103 -0
- workos/types/events/event_type.py +59 -0
- workos/types/events/list_filters.py +10 -0
- workos/types/events/organization_domain_verification_failed_payload.py +14 -0
- workos/types/events/previous_attributes.py +3 -0
- workos/types/events/session_payload.py +27 -0
- workos/types/feature_flags/__init__.py +3 -0
- workos/types/feature_flags/feature_flag.py +12 -0
- workos/types/feature_flags/list_filters.py +5 -0
- workos/types/fga/__init__.py +5 -0
- workos/types/fga/authorization_resource_types.py +9 -0
- workos/types/fga/authorization_resources.py +10 -0
- workos/types/fga/check.py +51 -0
- workos/types/fga/list_filters.py +24 -0
- workos/types/fga/warnings.py +33 -0
- workos/types/fga/warrant.py +49 -0
- workos/types/list_resource.py +198 -0
- workos/types/metadata.py +4 -0
- workos/types/mfa/__init__.py +5 -0
- workos/types/mfa/authentication_challenge.py +14 -0
- workos/types/mfa/authentication_challenge_verification_response.py +9 -0
- workos/types/mfa/authentication_factor.py +70 -0
- workos/types/mfa/authentication_factor_totp_and_challenge_response.py +10 -0
- workos/types/mfa/enroll_authentication_factor_type.py +8 -0
- workos/types/organization_domains/__init__.py +1 -0
- workos/types/organization_domains/organization_domain.py +18 -0
- workos/types/organizations/__init__.py +6 -0
- workos/types/organizations/domain_data_input.py +7 -0
- workos/types/organizations/list_filters.py +6 -0
- workos/types/organizations/organization.py +13 -0
- workos/types/organizations/organization_common.py +12 -0
- workos/types/passwordless/__init__.py +2 -0
- workos/types/passwordless/passwordless_session.py +12 -0
- workos/types/passwordless/passwordless_session_type.py +3 -0
- workos/types/pipes/__init__.py +6 -0
- workos/types/pipes/pipes.py +34 -0
- workos/types/portal/__init__.py +2 -0
- workos/types/portal/portal_link.py +7 -0
- workos/types/portal/portal_link_intent.py +11 -0
- workos/types/portal/portal_link_intent_options.py +9 -0
- workos/types/roles/__init__.py +0 -0
- workos/types/roles/role.py +27 -0
- workos/types/sso/__init__.py +4 -0
- workos/types/sso/connection.py +70 -0
- workos/types/sso/connection_domain.py +8 -0
- workos/types/sso/profile.py +35 -0
- workos/types/sso/sso_provider_type.py +10 -0
- workos/types/user_management/__init__.py +12 -0
- workos/types/user_management/authenticate_with_common.py +66 -0
- workos/types/user_management/authentication_response.py +53 -0
- workos/types/user_management/email_verification.py +18 -0
- workos/types/user_management/impersonator.py +8 -0
- workos/types/user_management/invitation.py +26 -0
- workos/types/user_management/list_filters.py +29 -0
- workos/types/user_management/magic_auth.py +18 -0
- workos/types/user_management/oauth_tokens.py +21 -0
- workos/types/user_management/organization_membership.py +25 -0
- workos/types/user_management/password_hash_type.py +4 -0
- workos/types/user_management/password_reset.py +18 -0
- workos/types/user_management/screen_hint.py +3 -0
- workos/types/user_management/session.py +79 -0
- workos/types/user_management/user.py +22 -0
- workos/types/user_management/user_management_provider_type.py +11 -0
- workos/types/vault/__init__.py +2 -0
- workos/types/vault/key.py +25 -0
- workos/types/vault/object.py +38 -0
- workos/types/webhooks/__init__.py +0 -0
- workos/types/webhooks/webhook.py +330 -0
- workos/types/webhooks/webhook_model.py +14 -0
- workos/types/webhooks/webhook_payload.py +4 -0
- workos/types/widgets/__init__.py +2 -0
- workos/types/widgets/widget_scope.py +4 -0
- workos/types/widgets/widget_token_response.py +7 -0
- workos/types/workos_model.py +26 -0
- workos/typing/__init__.py +1 -0
- workos/typing/literals.py +32 -0
- workos/typing/sync_or_async.py +5 -0
- workos/typing/untyped_literal.py +37 -0
- workos/typing/webhooks.py +18 -0
- workos/user_management.py +2400 -0
- workos/utils/_base_http_client.py +252 -0
- workos/utils/crypto_provider.py +39 -0
- workos/utils/http_client.py +214 -0
- workos/utils/pagination_order.py +4 -0
- workos/utils/request_helper.py +27 -0
- workos/vault.py +544 -0
- workos/webhooks.py +96 -39
- workos/widgets.py +55 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/LICENSE +1 -1
- workos-5.38.0.dist-info/METADATA +107 -0
- workos-5.38.0.dist-info/RECORD +141 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/WHEEL +1 -1
- workos/audit_trail.py +0 -172
- workos/resources/base.py +0 -36
- workos/resources/event.py +0 -42
- workos/resources/event_action.py +0 -11
- workos/resources/sso.py +0 -53
- workos/utils/connection_types.py +0 -17
- workos/utils/request.py +0 -95
- workos/utils/validation.py +0 -45
- workos-1.5.1.dist-info/METADATA +0 -77
- workos-1.5.1.dist-info/RECORD +0 -25
- /workos/{resources/__init__.py → py.typed} +0 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from typing import Generic, Literal, TypeVar
|
|
2
|
+
from workos.types.user_management import OrganizationMembership, User
|
|
3
|
+
from workos.types.workos_model import WorkOSModel
|
|
4
|
+
from workos.types.directory_sync.directory_group import DirectoryGroup
|
|
5
|
+
from workos.types.directory_sync.directory_user import DirectoryUser
|
|
6
|
+
from workos.types.events.authentication_payload import (
|
|
7
|
+
AuthenticationEmailVerificationSucceededPayload,
|
|
8
|
+
AuthenticationMagicAuthFailedPayload,
|
|
9
|
+
AuthenticationMagicAuthSucceededPayload,
|
|
10
|
+
AuthenticationMfaSucceededPayload,
|
|
11
|
+
AuthenticationOauthFailedPayload,
|
|
12
|
+
AuthenticationOauthSucceededPayload,
|
|
13
|
+
AuthenticationPasswordFailedPayload,
|
|
14
|
+
AuthenticationPasswordSucceededPayload,
|
|
15
|
+
AuthenticationSsoFailedPayload,
|
|
16
|
+
AuthenticationSsoSucceededPayload,
|
|
17
|
+
)
|
|
18
|
+
from workos.types.events.connection_payload_with_legacy_fields import (
|
|
19
|
+
ConnectionPayloadWithLegacyFields,
|
|
20
|
+
)
|
|
21
|
+
from workos.types.events.directory_group_membership_payload import (
|
|
22
|
+
DirectoryGroupMembershipPayload,
|
|
23
|
+
)
|
|
24
|
+
from workos.types.events.directory_group_with_previous_attributes import (
|
|
25
|
+
DirectoryGroupWithPreviousAttributes,
|
|
26
|
+
)
|
|
27
|
+
from workos.types.events.directory_payload import DirectoryPayload
|
|
28
|
+
from workos.types.events.directory_payload_with_legacy_fields import (
|
|
29
|
+
DirectoryPayloadWithLegacyFields,
|
|
30
|
+
DirectoryPayloadWithLegacyFieldsForEventsApi,
|
|
31
|
+
)
|
|
32
|
+
from workos.types.events.directory_user_with_previous_attributes import (
|
|
33
|
+
DirectoryUserWithPreviousAttributes,
|
|
34
|
+
)
|
|
35
|
+
from workos.types.events.organization_domain_verification_failed_payload import (
|
|
36
|
+
OrganizationDomainVerificationFailedPayload,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
from workos.types.events.session_payload import (
|
|
40
|
+
SessionCreatedPayload,
|
|
41
|
+
SessionRevokedPayload,
|
|
42
|
+
)
|
|
43
|
+
from workos.types.organizations.organization_common import OrganizationCommon
|
|
44
|
+
from workos.types.organization_domains import OrganizationDomain
|
|
45
|
+
from workos.types.roles.role import EventRole
|
|
46
|
+
from workos.types.sso.connection import Connection
|
|
47
|
+
from workos.types.user_management.email_verification import (
|
|
48
|
+
EmailVerificationCommon,
|
|
49
|
+
)
|
|
50
|
+
from workos.types.user_management.invitation import InvitationCommon
|
|
51
|
+
from workos.types.user_management.magic_auth import MagicAuthCommon
|
|
52
|
+
from workos.types.user_management.password_reset import PasswordResetCommon
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
EventPayload = TypeVar(
|
|
56
|
+
"EventPayload",
|
|
57
|
+
AuthenticationEmailVerificationSucceededPayload,
|
|
58
|
+
AuthenticationMagicAuthFailedPayload,
|
|
59
|
+
AuthenticationMagicAuthSucceededPayload,
|
|
60
|
+
AuthenticationMfaSucceededPayload,
|
|
61
|
+
AuthenticationOauthFailedPayload,
|
|
62
|
+
AuthenticationOauthSucceededPayload,
|
|
63
|
+
AuthenticationPasswordFailedPayload,
|
|
64
|
+
AuthenticationPasswordSucceededPayload,
|
|
65
|
+
AuthenticationSsoFailedPayload,
|
|
66
|
+
AuthenticationSsoSucceededPayload,
|
|
67
|
+
Connection,
|
|
68
|
+
ConnectionPayloadWithLegacyFields,
|
|
69
|
+
DirectoryPayload,
|
|
70
|
+
DirectoryPayloadWithLegacyFields,
|
|
71
|
+
# TODO: Remove once merged with DirectoryPayloadWithLegacyFields in next major release.
|
|
72
|
+
DirectoryPayloadWithLegacyFieldsForEventsApi,
|
|
73
|
+
DirectoryGroup,
|
|
74
|
+
DirectoryGroupWithPreviousAttributes,
|
|
75
|
+
DirectoryUser,
|
|
76
|
+
DirectoryUserWithPreviousAttributes,
|
|
77
|
+
DirectoryGroupMembershipPayload,
|
|
78
|
+
EmailVerificationCommon,
|
|
79
|
+
EventRole,
|
|
80
|
+
InvitationCommon,
|
|
81
|
+
MagicAuthCommon,
|
|
82
|
+
OrganizationCommon,
|
|
83
|
+
OrganizationDomain,
|
|
84
|
+
OrganizationDomainVerificationFailedPayload,
|
|
85
|
+
OrganizationMembership,
|
|
86
|
+
PasswordResetCommon,
|
|
87
|
+
SessionCreatedPayload,
|
|
88
|
+
SessionRevokedPayload,
|
|
89
|
+
User,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class EventModel(WorkOSModel, Generic[EventPayload]):
|
|
94
|
+
# TODO: fix these docs
|
|
95
|
+
"""Representation of an Event returned from the Events API or via Webhook.
|
|
96
|
+
Attributes:
|
|
97
|
+
OBJECT_FIELDS (list): List of fields an Event is comprised of.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
id: str
|
|
101
|
+
object: Literal["event"]
|
|
102
|
+
data: EventPayload
|
|
103
|
+
created_at: str
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from typing import Literal, TypeVar
|
|
2
|
+
|
|
3
|
+
# README
|
|
4
|
+
# When adding a new event type, ensure a new event class is created
|
|
5
|
+
# and added to the Event class union type in event.py.
|
|
6
|
+
|
|
7
|
+
EventType = Literal[
|
|
8
|
+
"authentication.email_verification_succeeded",
|
|
9
|
+
"authentication.magic_auth_failed",
|
|
10
|
+
"authentication.magic_auth_succeeded",
|
|
11
|
+
"authentication.mfa_succeeded",
|
|
12
|
+
"authentication.oauth_failed",
|
|
13
|
+
"authentication.oauth_succeeded",
|
|
14
|
+
"authentication.password_failed",
|
|
15
|
+
"authentication.password_succeeded",
|
|
16
|
+
"authentication.sso_failed",
|
|
17
|
+
"authentication.sso_succeeded",
|
|
18
|
+
"connection.activated",
|
|
19
|
+
"connection.deactivated",
|
|
20
|
+
"connection.deleted",
|
|
21
|
+
"dsync.activated",
|
|
22
|
+
"dsync.deleted",
|
|
23
|
+
"dsync.group.created",
|
|
24
|
+
"dsync.group.deleted",
|
|
25
|
+
"dsync.group.updated",
|
|
26
|
+
"dsync.user.created",
|
|
27
|
+
"dsync.user.deleted",
|
|
28
|
+
"dsync.user.updated",
|
|
29
|
+
"dsync.group.user_added",
|
|
30
|
+
"dsync.group.user_removed",
|
|
31
|
+
"email_verification.created",
|
|
32
|
+
"invitation.accepted",
|
|
33
|
+
"invitation.created",
|
|
34
|
+
"invitation.revoked",
|
|
35
|
+
"magic_auth.created",
|
|
36
|
+
"organization.created",
|
|
37
|
+
"organization.deleted",
|
|
38
|
+
"organization.updated",
|
|
39
|
+
"organization_domain.verification_failed",
|
|
40
|
+
"organization_domain.verified",
|
|
41
|
+
"organization_domain.created",
|
|
42
|
+
"organization_domain.deleted",
|
|
43
|
+
"organization_domain.updated",
|
|
44
|
+
"organization_membership.created",
|
|
45
|
+
"organization_membership.deleted",
|
|
46
|
+
"organization_membership.updated",
|
|
47
|
+
"password_reset.created",
|
|
48
|
+
"password_reset.succeeded",
|
|
49
|
+
"role.created",
|
|
50
|
+
"role.deleted",
|
|
51
|
+
"role.updated",
|
|
52
|
+
"session.created",
|
|
53
|
+
"session.revoked",
|
|
54
|
+
"user.created",
|
|
55
|
+
"user.deleted",
|
|
56
|
+
"user.updated",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
EventTypeDiscriminator = TypeVar("EventTypeDiscriminator", bound=EventType)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from typing import Optional, Sequence
|
|
2
|
+
from workos.types.events import EventType
|
|
3
|
+
from workos.types.list_resource import ListArgs
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class EventsListFilters(ListArgs, total=False):
|
|
7
|
+
events: Sequence[EventType]
|
|
8
|
+
organization_id: Optional[str]
|
|
9
|
+
range_start: Optional[str]
|
|
10
|
+
range_end: Optional[str]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
from workos.types.workos_model import WorkOSModel
|
|
3
|
+
from workos.types.organization_domains import OrganizationDomain
|
|
4
|
+
from workos.typing.literals import LiteralOrUntyped
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class OrganizationDomainVerificationFailedPayload(WorkOSModel):
|
|
8
|
+
reason: LiteralOrUntyped[
|
|
9
|
+
Literal[
|
|
10
|
+
"domain_verification_period_expired",
|
|
11
|
+
"domain_verified_by_other_organization",
|
|
12
|
+
]
|
|
13
|
+
]
|
|
14
|
+
organization_domain: OrganizationDomain
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
from workos.types.workos_model import WorkOSModel
|
|
3
|
+
from workos.types.user_management.impersonator import Impersonator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SessionCreatedPayload(WorkOSModel):
|
|
7
|
+
object: Literal["session"]
|
|
8
|
+
id: str
|
|
9
|
+
impersonator: Optional[Impersonator] = None
|
|
10
|
+
ip_address: Optional[str] = None
|
|
11
|
+
organization_id: Optional[str] = None
|
|
12
|
+
user_agent: Optional[str] = None
|
|
13
|
+
user_id: str
|
|
14
|
+
created_at: str
|
|
15
|
+
updated_at: str
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SessionRevokedPayload(WorkOSModel):
|
|
19
|
+
object: Literal["session"]
|
|
20
|
+
id: str
|
|
21
|
+
impersonator: Optional[Impersonator] = None
|
|
22
|
+
ip_address: Optional[str] = None
|
|
23
|
+
organization_id: Optional[str] = None
|
|
24
|
+
user_agent: Optional[str] = None
|
|
25
|
+
user_id: str
|
|
26
|
+
created_at: str
|
|
27
|
+
updated_at: str
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
from workos.types.workos_model import WorkOSModel
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class FeatureFlag(WorkOSModel):
|
|
6
|
+
id: str
|
|
7
|
+
object: Literal["feature_flag"]
|
|
8
|
+
slug: str
|
|
9
|
+
name: str
|
|
10
|
+
description: Optional[str]
|
|
11
|
+
created_at: str
|
|
12
|
+
updated_at: str
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from typing import Any, Mapping, Optional
|
|
2
|
+
|
|
3
|
+
from workos.types.workos_model import WorkOSModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthorizationResource(WorkOSModel):
|
|
7
|
+
resource_type: str
|
|
8
|
+
resource_id: str
|
|
9
|
+
meta: Optional[Mapping[str, Any]] = None
|
|
10
|
+
created_at: Optional[str] = None
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Any, Literal, Mapping, Optional, Sequence, TypedDict
|
|
2
|
+
|
|
3
|
+
from workos.types.workos_model import WorkOSModel
|
|
4
|
+
from workos.typing.literals import LiteralOrUntyped
|
|
5
|
+
|
|
6
|
+
from .warnings import FGAWarning
|
|
7
|
+
from .warrant import Subject, SubjectInput
|
|
8
|
+
|
|
9
|
+
CheckOperation = Literal["any_of", "all_of", "batch"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WarrantCheckInput(TypedDict, total=False):
|
|
13
|
+
resource_type: str
|
|
14
|
+
resource_id: str
|
|
15
|
+
relation: str
|
|
16
|
+
subject: SubjectInput
|
|
17
|
+
context: Optional[Mapping[str, Any]]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class WarrantCheck(WorkOSModel):
|
|
21
|
+
resource_type: str
|
|
22
|
+
resource_id: str
|
|
23
|
+
relation: str
|
|
24
|
+
subject: Subject
|
|
25
|
+
context: Optional[Mapping[str, Any]] = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DecisionTreeNode(WorkOSModel):
|
|
29
|
+
check: WarrantCheck
|
|
30
|
+
decision: str
|
|
31
|
+
processing_time: int
|
|
32
|
+
children: Optional[Sequence["DecisionTreeNode"]] = None
|
|
33
|
+
policy: Optional[str] = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class DebugInfo(WorkOSModel):
|
|
37
|
+
processing_time: int
|
|
38
|
+
decision_tree: DecisionTreeNode
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
CheckResult = Literal["authorized", "not_authorized"]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class CheckResponse(WorkOSModel):
|
|
45
|
+
result: LiteralOrUntyped[CheckResult]
|
|
46
|
+
is_implicit: bool
|
|
47
|
+
debug_info: Optional[DebugInfo] = None
|
|
48
|
+
warnings: Optional[Sequence[FGAWarning]] = None
|
|
49
|
+
|
|
50
|
+
def authorized(self) -> bool:
|
|
51
|
+
return self.result == "authorized"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Mapping, Optional, Any
|
|
2
|
+
|
|
3
|
+
from workos.types.list_resource import ListArgs
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthorizationResourceListFilters(ListArgs, total=False):
|
|
7
|
+
resource_type: Optional[str]
|
|
8
|
+
search: Optional[str]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WarrantListFilters(ListArgs, total=False):
|
|
12
|
+
resource_type: Optional[str]
|
|
13
|
+
resource_id: Optional[str]
|
|
14
|
+
relation: Optional[str]
|
|
15
|
+
subject_type: Optional[str]
|
|
16
|
+
subject_id: Optional[str]
|
|
17
|
+
subject_relation: Optional[str]
|
|
18
|
+
warrant_token: Optional[str]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WarrantQueryListFilters(ListArgs, total=False):
|
|
22
|
+
q: Optional[str]
|
|
23
|
+
context: Optional[Mapping[str, Any]]
|
|
24
|
+
warrant_token: Optional[str]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import Sequence, Union, Any, Dict, Literal
|
|
2
|
+
from typing_extensions import Annotated
|
|
3
|
+
|
|
4
|
+
from pydantic import BeforeValidator
|
|
5
|
+
from pydantic_core.core_schema import ValidationInfo
|
|
6
|
+
|
|
7
|
+
from workos.types.workos_model import WorkOSModel
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FGABaseWarning(WorkOSModel):
|
|
11
|
+
code: str
|
|
12
|
+
message: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MissingContextKeysWarning(FGABaseWarning):
|
|
16
|
+
code: Literal["missing_context_keys"]
|
|
17
|
+
keys: Sequence[str]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def fga_warning_dispatch_validator(
|
|
21
|
+
value: Dict[str, Any], info: ValidationInfo
|
|
22
|
+
) -> FGABaseWarning:
|
|
23
|
+
if value.get("code") == "missing_context_keys":
|
|
24
|
+
return MissingContextKeysWarning.model_validate(value)
|
|
25
|
+
|
|
26
|
+
# Fallback to the base warning model
|
|
27
|
+
return FGABaseWarning.model_validate(value)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
FGAWarning = Annotated[
|
|
31
|
+
Union[MissingContextKeysWarning, FGABaseWarning],
|
|
32
|
+
BeforeValidator(fga_warning_dispatch_validator),
|
|
33
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from typing import Literal, Mapping, Optional, Any
|
|
2
|
+
from typing_extensions import TypedDict
|
|
3
|
+
|
|
4
|
+
from workos.types.workos_model import WorkOSModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SubjectInput(TypedDict, total=False):
|
|
8
|
+
resource_type: str
|
|
9
|
+
resource_id: str
|
|
10
|
+
relation: Optional[str]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Subject(WorkOSModel):
|
|
14
|
+
resource_type: str
|
|
15
|
+
resource_id: str
|
|
16
|
+
relation: Optional[str] = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Warrant(WorkOSModel):
|
|
20
|
+
resource_type: str
|
|
21
|
+
resource_id: str
|
|
22
|
+
relation: str
|
|
23
|
+
subject: Subject
|
|
24
|
+
policy: Optional[str] = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class WriteWarrantResponse(WorkOSModel):
|
|
28
|
+
warrant_token: str
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
WarrantWriteOperation = Literal["create", "delete"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class WarrantWrite(TypedDict, total=False):
|
|
35
|
+
op: WarrantWriteOperation
|
|
36
|
+
resource_type: str
|
|
37
|
+
resource_id: str
|
|
38
|
+
relation: str
|
|
39
|
+
subject: SubjectInput
|
|
40
|
+
policy: Optional[str]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class WarrantQueryResult(WorkOSModel):
|
|
44
|
+
resource_type: str
|
|
45
|
+
resource_id: str
|
|
46
|
+
relation: str
|
|
47
|
+
warrant: Warrant
|
|
48
|
+
is_implicit: bool
|
|
49
|
+
meta: Optional[Mapping[str, Any]] = None
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import (
|
|
3
|
+
Any,
|
|
4
|
+
Awaitable,
|
|
5
|
+
AsyncIterator,
|
|
6
|
+
Dict,
|
|
7
|
+
Literal,
|
|
8
|
+
Mapping,
|
|
9
|
+
Sequence,
|
|
10
|
+
Tuple,
|
|
11
|
+
TypeVar,
|
|
12
|
+
Generic,
|
|
13
|
+
Callable,
|
|
14
|
+
Iterator,
|
|
15
|
+
Optional,
|
|
16
|
+
Union,
|
|
17
|
+
cast,
|
|
18
|
+
)
|
|
19
|
+
from typing_extensions import Required, TypedDict
|
|
20
|
+
from workos.types.directory_sync import (
|
|
21
|
+
Directory,
|
|
22
|
+
DirectoryGroup,
|
|
23
|
+
DirectoryUserWithGroups,
|
|
24
|
+
)
|
|
25
|
+
from workos.types.events import Event
|
|
26
|
+
from workos.types.feature_flags import FeatureFlag
|
|
27
|
+
from workos.types.fga import (
|
|
28
|
+
Warrant,
|
|
29
|
+
AuthorizationResource,
|
|
30
|
+
AuthorizationResourceType,
|
|
31
|
+
WarrantQueryResult,
|
|
32
|
+
)
|
|
33
|
+
from workos.types.mfa import AuthenticationFactor
|
|
34
|
+
from workos.types.organizations import Organization
|
|
35
|
+
from workos.types.sso import ConnectionWithDomains
|
|
36
|
+
from workos.types.user_management import Invitation, OrganizationMembership, User
|
|
37
|
+
from workos.types.user_management.session import Session as UserManagementSession
|
|
38
|
+
from workos.types.vault import ObjectDigest
|
|
39
|
+
from workos.types.workos_model import WorkOSModel
|
|
40
|
+
from workos.utils.request_helper import DEFAULT_LIST_RESPONSE_LIMIT
|
|
41
|
+
|
|
42
|
+
ListableResource = TypeVar(
|
|
43
|
+
# add all possible generics of List Resource
|
|
44
|
+
"ListableResource",
|
|
45
|
+
AuthenticationFactor,
|
|
46
|
+
ConnectionWithDomains,
|
|
47
|
+
Directory,
|
|
48
|
+
DirectoryGroup,
|
|
49
|
+
DirectoryUserWithGroups,
|
|
50
|
+
Event,
|
|
51
|
+
FeatureFlag,
|
|
52
|
+
Invitation,
|
|
53
|
+
Organization,
|
|
54
|
+
OrganizationMembership,
|
|
55
|
+
AuthorizationResource,
|
|
56
|
+
AuthorizationResourceType,
|
|
57
|
+
User,
|
|
58
|
+
UserManagementSession,
|
|
59
|
+
ObjectDigest,
|
|
60
|
+
Warrant,
|
|
61
|
+
WarrantQueryResult,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ListAfterMetadata(BaseModel):
|
|
66
|
+
after: Optional[str] = None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class ListMetadata(ListAfterMetadata):
|
|
70
|
+
before: Optional[str] = None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
ListMetadataType = TypeVar("ListMetadataType", ListAfterMetadata, ListMetadata)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ListPage(WorkOSModel, Generic[ListableResource]):
|
|
77
|
+
object: Literal["list"]
|
|
78
|
+
data: Sequence[ListableResource]
|
|
79
|
+
list_metadata: ListMetadata
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class ListArgs(TypedDict, total=False):
|
|
83
|
+
before: Optional[str]
|
|
84
|
+
after: Optional[str]
|
|
85
|
+
limit: Required[int]
|
|
86
|
+
order: Optional[Literal["asc", "desc"]]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
ListAndFilterParams = TypeVar("ListAndFilterParams", bound=ListArgs)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class WorkOSListResource(
|
|
93
|
+
WorkOSModel,
|
|
94
|
+
Generic[ListableResource, ListAndFilterParams, ListMetadataType],
|
|
95
|
+
):
|
|
96
|
+
object: Literal["list"]
|
|
97
|
+
data: Sequence[ListableResource]
|
|
98
|
+
list_metadata: ListMetadataType
|
|
99
|
+
|
|
100
|
+
# TODO: Fix type hinting for list_method to support both sync and async
|
|
101
|
+
list_method: Union[
|
|
102
|
+
Callable[
|
|
103
|
+
...,
|
|
104
|
+
"WorkOSListResource[ListableResource, ListAndFilterParams, ListMetadataType]",
|
|
105
|
+
],
|
|
106
|
+
Callable[
|
|
107
|
+
...,
|
|
108
|
+
"Awaitable[WorkOSListResource[ListableResource, ListAndFilterParams, ListMetadataType]]",
|
|
109
|
+
],
|
|
110
|
+
] = Field(exclude=True)
|
|
111
|
+
list_args: ListAndFilterParams = Field(exclude=True)
|
|
112
|
+
|
|
113
|
+
def _parse_params(
|
|
114
|
+
self, limit_override: Optional[int] = None
|
|
115
|
+
) -> Tuple[Dict[str, Union[int, str, None]], Mapping[str, Any]]:
|
|
116
|
+
fixed_pagination_params = cast(
|
|
117
|
+
# Type hints consider this a mismatch because it assume the dictionary is dict[str, int]
|
|
118
|
+
Dict[str, Union[int, str, None]],
|
|
119
|
+
{
|
|
120
|
+
"limit": limit_override or self.list_args["limit"],
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
if "order" in self.list_args:
|
|
124
|
+
fixed_pagination_params["order"] = self.list_args["order"]
|
|
125
|
+
|
|
126
|
+
# Omit common list parameters
|
|
127
|
+
filter_params = {
|
|
128
|
+
k: v
|
|
129
|
+
for k, v in self.list_args.items()
|
|
130
|
+
if k not in {"order", "limit", "before", "after"}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return fixed_pagination_params, filter_params
|
|
134
|
+
|
|
135
|
+
# Pydantic uses a custom `__iter__` method to support casting BaseModels
|
|
136
|
+
# to dictionaries. e.g. dict(model).
|
|
137
|
+
# As we want to support `for item in page`, this is inherently incompatible
|
|
138
|
+
# with the default pydantic behaviour. It is not possible to support both
|
|
139
|
+
# use cases at once. Fortunately, this is not a big deal as all other pydantic
|
|
140
|
+
# methods should continue to work as expected as there is an alternative method
|
|
141
|
+
# to cast a model to a dictionary, model.dict(), which is used internally
|
|
142
|
+
# by pydantic.
|
|
143
|
+
def __iter__(self) -> Iterator[ListableResource]: # type: ignore
|
|
144
|
+
next_page: WorkOSListResource[
|
|
145
|
+
ListableResource, ListAndFilterParams, ListMetadataType
|
|
146
|
+
]
|
|
147
|
+
after = self.list_metadata.after
|
|
148
|
+
fixed_pagination_params, filter_params = self._parse_params(
|
|
149
|
+
# Singe we're auto-paginating, ignore the original limit and use the default
|
|
150
|
+
limit_override=DEFAULT_LIST_RESPONSE_LIMIT
|
|
151
|
+
)
|
|
152
|
+
index: int = 0
|
|
153
|
+
|
|
154
|
+
while True:
|
|
155
|
+
if index >= len(self.data):
|
|
156
|
+
if after is not None:
|
|
157
|
+
# TODO: Fix type hinting for list_method to support both sync and async
|
|
158
|
+
# We use a union to support both sync and async methods,
|
|
159
|
+
# but when we get to the particular implementation, it
|
|
160
|
+
# doesn't know which one it is. It's safe, but should be fixed.
|
|
161
|
+
next_page = self.list_method(
|
|
162
|
+
after=after, **fixed_pagination_params, **filter_params
|
|
163
|
+
) # type: ignore
|
|
164
|
+
self.data = next_page.data
|
|
165
|
+
after = next_page.list_metadata.after
|
|
166
|
+
index = 0
|
|
167
|
+
continue
|
|
168
|
+
else:
|
|
169
|
+
return
|
|
170
|
+
yield self.data[index]
|
|
171
|
+
index += 1
|
|
172
|
+
|
|
173
|
+
async def __aiter__(self) -> AsyncIterator[ListableResource]:
|
|
174
|
+
next_page: WorkOSListResource[
|
|
175
|
+
ListableResource, ListAndFilterParams, ListMetadataType
|
|
176
|
+
]
|
|
177
|
+
after = self.list_metadata.after
|
|
178
|
+
fixed_pagination_params, filter_params = self._parse_params()
|
|
179
|
+
index: int = 0
|
|
180
|
+
|
|
181
|
+
while True:
|
|
182
|
+
if index >= len(self.data):
|
|
183
|
+
if after is not None:
|
|
184
|
+
# TODO: Fix type hinting for list_method to support both sync and async
|
|
185
|
+
# We use a union to support both sync and async methods,
|
|
186
|
+
# but when we get to the particular implementation, it
|
|
187
|
+
# doesn't know which one it is. It's safe, but should be fixed.
|
|
188
|
+
next_page = await self.list_method(
|
|
189
|
+
after=after, **fixed_pagination_params, **filter_params
|
|
190
|
+
) # type: ignore
|
|
191
|
+
self.data = next_page.data
|
|
192
|
+
after = next_page.list_metadata.after
|
|
193
|
+
index = 0
|
|
194
|
+
continue
|
|
195
|
+
else:
|
|
196
|
+
return
|
|
197
|
+
yield self.data[index]
|
|
198
|
+
index += 1
|
workos/types/metadata.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
from workos.types.workos_model import WorkOSModel
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AuthenticationChallenge(WorkOSModel):
|
|
6
|
+
"""Representation of a MFA Challenge Response as returned by WorkOS through the MFA feature."""
|
|
7
|
+
|
|
8
|
+
object: Literal["authentication_challenge"]
|
|
9
|
+
id: str
|
|
10
|
+
created_at: str
|
|
11
|
+
updated_at: str
|
|
12
|
+
expires_at: Optional[str] = None
|
|
13
|
+
code: Optional[str] = None
|
|
14
|
+
authentication_factor_id: str
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from workos.types.workos_model import WorkOSModel
|
|
2
|
+
from workos.types.mfa.authentication_challenge import AuthenticationChallenge
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AuthenticationChallengeVerificationResponse(WorkOSModel):
|
|
6
|
+
"""Representation of a WorkOS MFA Challenge Verification Response."""
|
|
7
|
+
|
|
8
|
+
challenge: AuthenticationChallenge
|
|
9
|
+
valid: bool
|