From d815e0b42a89708dbead50f36a1a5171318756d4 Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:21:09 -0700 Subject: [PATCH 1/8] Audit logs QOL improvements --- workos/audit_logs.py | 40 ++++++++++++++++++++++++++++++++-- workos/resources/audit_logs.py | 35 ----------------------------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/workos/audit_logs.py b/workos/audit_logs.py index 2bb51a9d..1828c919 100644 --- a/workos/audit_logs.py +++ b/workos/audit_logs.py @@ -1,7 +1,8 @@ -from typing import Optional, Protocol, Sequence +from typing import NotRequired, Optional, Protocol, Sequence +from typing_extensions import TypedDict import workos -from workos.resources.audit_logs import AuditLogEvent, AuditLogExport +from workos.resources.audit_logs import AuditLogExport from workos.utils.http_client import SyncHTTPClient from workos.utils.request_helper import REQUEST_METHOD_GET, REQUEST_METHOD_POST from workos.utils.validation import AUDIT_LOGS_MODULE, validate_settings @@ -10,6 +11,41 @@ EXPORTS_PATH = "audit_logs/exports" +class AuditLogEventTarget(TypedDict): + """Describes the entity that was targeted by the event.""" + + id: str + metadata: NotRequired[dict] + name: NotRequired[str] + type: str + + +class AuditLogEventActor(TypedDict): + """Describes the entity that generated the event.""" + + id: str + metadata: NotRequired[dict] + name: NotRequired[str] + type: str + + +class AuditLogEventContext(TypedDict): + """Attributes of audit log event context.""" + + location: str + user_agent: NotRequired[str] + + +class AuditLogEvent(TypedDict): + action: str + version: NotRequired[int] + occurred_at: str # ISO-8601 datetime of when an event occurred + actor: AuditLogEventActor + targets: Sequence[AuditLogEventTarget] + context: AuditLogEventContext + metadata: NotRequired[dict] + + class AuditLogsModule(Protocol): def create_event( self, diff --git a/workos/resources/audit_logs.py b/workos/resources/audit_logs.py index e4c560e0..f37d9874 100644 --- a/workos/resources/audit_logs.py +++ b/workos/resources/audit_logs.py @@ -15,38 +15,3 @@ class AuditLogExport(WorkOSModel): updated_at: str state: AuditLogExportState url: Optional[str] = None - - -class AuditLogEventActor(TypedDict): - """Describes the entity that generated the event.""" - - id: str - metadata: NotRequired[dict] - name: NotRequired[str] - type: str - - -class AuditLogEventTarget(TypedDict): - """Describes the entity that was targeted by the event.""" - - id: str - metadata: NotRequired[dict] - name: NotRequired[str] - type: str - - -class AuditLogEventContext(TypedDict): - """Attributes of audit log event context.""" - - location: str - user_agent: NotRequired[str] - - -class AuditLogEvent(TypedDict): - action: str - version: NotRequired[int] - occurred_at: str # ISO-8601 datetime of when an event occurred - actor: AuditLogEventActor - targets: Sequence[AuditLogEventTarget] - context: AuditLogEventContext - metadata: NotRequired[dict] From 21f261b007a9d5567a47297eaec8d3a45831b095 Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:28:47 -0700 Subject: [PATCH 2/8] Events and MFA QoL improvements --- workos/events.py | 48 ++++++++++++++++++++++++++++++++++++-- workos/mfa.py | 9 +++++-- workos/resources/events.py | 46 ++---------------------------------- workos/resources/mfa.py | 3 --- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/workos/events.py b/workos/events.py index 05ad493d..5954608c 100644 --- a/workos/events.py +++ b/workos/events.py @@ -1,9 +1,9 @@ -from typing import Optional, Protocol, Sequence, Union +from typing import Literal, Optional, Protocol, Sequence, Union import workos from workos.typing.sync_or_async import SyncOrAsync from workos.utils.request_helper import DEFAULT_LIST_RESPONSE_LIMIT, REQUEST_METHOD_GET -from workos.resources.events import Event, EventType +from workos.resources.events import Event from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.validation import EVENTS_MODULE, validate_settings from workos.resources.list import ( @@ -15,6 +15,50 @@ ) +EventType = Literal[ + "authentication.email_verification_succeeded", + "authentication.magic_auth_failed", + "authentication.magic_auth_succeeded", + "authentication.mfa_succeeded", + "authentication.oauth_succeeded", + "authentication.password_failed", + "authentication.password_succeeded", + "authentication.sso_succeeded", + "connection.activated", + "connection.deactivated", + "connection.deleted", + "dsync.activated", + "dsync.deleted", + "dsync.group.created", + "dsync.group.deleted", + "dsync.group.updated", + "dsync.user.created", + "dsync.user.deleted", + "dsync.user.updated", + "dsync.group.user_added", + "dsync.group.user_removed", + "email_verification.created", + "invitation.created", + "magic_auth.created", + "organization.created", + "organization.deleted", + "organization.updated", + "organization_domain.verification_failed", + "organization_domain.verified", + "organization_membership.created", + "organization_membership.deleted", + "organization_membership.updated", + "password_reset.created", + "role.created", + "role.deleted", + "role.updated", + "session.created", + "user.created", + "user.deleted", + "user.updated", +] + + class EventsListFilters(ListArgs, total=False): events: Sequence[EventType] organization_id: Optional[str] diff --git a/workos/mfa.py b/workos/mfa.py index 2f11a748..c6d03d19 100644 --- a/workos/mfa.py +++ b/workos/mfa.py @@ -1,4 +1,4 @@ -from typing import Optional, Protocol +from typing import Literal, Optional, Protocol import workos from workos.utils.http_client import SyncHTTPClient @@ -15,9 +15,14 @@ AuthenticationFactor, AuthenticationFactorSms, AuthenticationFactorTotp, - EnrollAuthenticationFactorType, + SmsAuthenticationFactorType, + TotpAuthenticationFactorType, ) +EnrollAuthenticationFactorType = Literal[ + SmsAuthenticationFactorType, TotpAuthenticationFactorType +] + class MFAModule(Protocol): def enroll_factor( diff --git a/workos/resources/events.py b/workos/resources/events.py index 81bfe3e1..2ed195ce 100644 --- a/workos/resources/events.py +++ b/workos/resources/events.py @@ -1,6 +1,7 @@ from typing import Generic, Literal, TypeVar, Union from typing_extensions import Annotated from pydantic import Field +from workos.events import EventType from workos.resources.directory_sync import DirectoryGroup from workos.resources.user_management import OrganizationMembership, User from workos.resources.workos_model import WorkOSModel @@ -45,50 +46,7 @@ from workos.types.user_management.invitation_common import InvitationCommon from workos.types.user_management.magic_auth_common import MagicAuthCommon from workos.types.user_management.password_reset_common import PasswordResetCommon -from workos.typing.literals import LiteralOrUntyped - -EventType = Literal[ - "authentication.email_verification_succeeded", - "authentication.magic_auth_failed", - "authentication.magic_auth_succeeded", - "authentication.mfa_succeeded", - "authentication.oauth_succeeded", - "authentication.password_failed", - "authentication.password_succeeded", - "authentication.sso_succeeded", - "connection.activated", - "connection.deactivated", - "connection.deleted", - "dsync.activated", - "dsync.deleted", - "dsync.group.created", - "dsync.group.deleted", - "dsync.group.updated", - "dsync.user.created", - "dsync.user.deleted", - "dsync.user.updated", - "dsync.group.user_added", - "dsync.group.user_removed", - "email_verification.created", - "invitation.created", - "magic_auth.created", - "organization.created", - "organization.deleted", - "organization.updated", - "organization_domain.verification_failed", - "organization_domain.verified", - "organization_membership.created", - "organization_membership.deleted", - "organization_membership.updated", - "password_reset.created", - "role.created", - "role.deleted", - "role.updated", - "session.created", - "user.created", - "user.deleted", - "user.updated", -] + EventTypeDiscriminator = TypeVar("EventTypeDiscriminator", bound=EventType) EventPayload = TypeVar( "EventPayload", diff --git a/workos/resources/mfa.py b/workos/resources/mfa.py index 4705ef59..edf23c75 100644 --- a/workos/resources/mfa.py +++ b/workos/resources/mfa.py @@ -7,9 +7,6 @@ AuthenticationFactorType = Literal[ "generic_otp", SmsAuthenticationFactorType, TotpAuthenticationFactorType ] -EnrollAuthenticationFactorType = Literal[ - SmsAuthenticationFactorType, TotpAuthenticationFactorType -] class TotpFactor(WorkOSModel): From 2764443c1c690bacdeb747741f36bcbb28f55fa2 Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:29:54 -0700 Subject: [PATCH 3/8] passwordless QoL improvements --- workos/passwordless.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/workos/passwordless.py b/workos/passwordless.py index e64f61f4..d941ff91 100644 --- a/workos/passwordless.py +++ b/workos/passwordless.py @@ -4,7 +4,9 @@ from workos.utils.http_client import SyncHTTPClient from workos.utils.request_helper import REQUEST_METHOD_POST from workos.utils.validation import PASSWORDLESS_MODULE, validate_settings -from workos.resources.passwordless import PasswordlessSession, PasswordlessSessionType +from workos.resources.passwordless import PasswordlessSession + +PasswordlessSessionType = Literal["MagicLink"] class PasswordlessModule(Protocol): From 638f9fcfe42ec4269b56e39da1679e75048dd4ad Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:32:10 -0700 Subject: [PATCH 4/8] SSO QoL improvements --- workos/resources/sso.py | 11 +------ workos/sso.py | 54 ++++++++++++++++++++++++++------ workos/utils/connection_types.py | 39 ----------------------- 3 files changed, 46 insertions(+), 58 deletions(-) delete mode 100644 workos/utils/connection_types.py diff --git a/workos/resources/sso.py b/workos/resources/sso.py index 931bf389..b5b2527e 100644 --- a/workos/resources/sso.py +++ b/workos/resources/sso.py @@ -1,9 +1,8 @@ from typing import Literal, Sequence, Union - from workos.resources.workos_model import WorkOSModel +from workos.sso import ConnectionType from workos.types.sso.connection import Connection from workos.typing.literals import LiteralOrUntyped -from workos.utils.connection_types import ConnectionType class Profile(WorkOSModel): @@ -39,11 +38,3 @@ class ConnectionWithDomains(Connection): """Representation of a Connection Response as returned by WorkOS through the SSO feature.""" domains: Sequence[ConnectionDomain] - - -SsoProviderType = Literal[ - "AppleOAuth", - "GitHubOAuth", - "GoogleOAuth", - "MicrosoftOAuth", -] diff --git a/workos/sso.py b/workos/sso.py index 8dddc8e8..71242617 100644 --- a/workos/sso.py +++ b/workos/sso.py @@ -1,16 +1,9 @@ -from typing import Optional, Protocol, Union - +from typing import Literal, Optional, Protocol, Union import workos from workos.typing.sync_or_async import SyncOrAsync from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.pagination_order import PaginationOrder -from workos.resources.sso import ( - ConnectionWithDomains, - Profile, - ProfileAndToken, - SsoProviderType, -) -from workos.utils.connection_types import ConnectionType +from workos.resources.sso import ConnectionWithDomains, Profile, ProfileAndToken from workos.utils.request_helper import ( DEFAULT_LIST_RESPONSE_LIMIT, RESPONSE_TYPE_CODE, @@ -34,6 +27,49 @@ PROFILE_PATH = "sso/profile" OAUTH_GRANT_TYPE = "authorization_code" +ConnectionType = Literal[ + "ADFSSAML", + "AdpOidc", + "AppleOAuth", + "Auth0SAML", + "AzureSAML", + "CasSAML", + "CloudflareSAML", + "ClassLinkSAML", + "CyberArkSAML", + "DuoSAML", + "GenericOIDC", + "GenericSAML", + "GitHubOAuth", + "GoogleOAuth", + "GoogleSAML", + "JumpCloudSAML", + "KeycloakSAML", + "LastPassSAML", + "LoginGovOidc", + "MagicLink", + "MicrosoftOAuth", + "MiniOrangeSAML", + "NetIqSAML", + "OktaSAML", + "OneLoginSAML", + "OracleSAML", + "PingFederateSAML", + "PingOneSAML", + "RipplingSAML", + "SalesforceSAML", + "ShibbolethGenericSAML", + "ShibbolethSAML", + "SimpleSamlPhpSAML", + "VMwareSAML", +] + +SsoProviderType = Literal[ + "AppleOAuth", + "GitHubOAuth", + "GoogleOAuth", + "MicrosoftOAuth", +] class ConnectionsListFilters(ListArgs, total=False): diff --git a/workos/utils/connection_types.py b/workos/utils/connection_types.py deleted file mode 100644 index 739026c4..00000000 --- a/workos/utils/connection_types.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import Literal - - -ConnectionType = Literal[ - "ADFSSAML", - "AdpOidc", - "AppleOAuth", - "Auth0SAML", - "AzureSAML", - "CasSAML", - "CloudflareSAML", - "ClassLinkSAML", - "CyberArkSAML", - "DuoSAML", - "GenericOIDC", - "GenericSAML", - "GitHubOAuth", - "GoogleOAuth", - "GoogleSAML", - "JumpCloudSAML", - "KeycloakSAML", - "LastPassSAML", - "LoginGovOidc", - "MagicLink", - "MicrosoftOAuth", - "MiniOrangeSAML", - "NetIqSAML", - "OktaSAML", - "OneLoginSAML", - "OracleSAML", - "PingFederateSAML", - "PingOneSAML", - "RipplingSAML", - "SalesforceSAML", - "ShibbolethGenericSAML", - "ShibbolethSAML", - "SimpleSamlPhpSAML", - "VMwareSAML", -] From 3714d623e70887dd6eeeac2ee62bd2e455bf080b Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:36:32 -0700 Subject: [PATCH 5/8] User management QoL improvements --- workos/resources/user_management.py | 7 +------ workos/user_management.py | 12 ++++++++---- workos/utils/um_provider_types.py | 6 ------ 3 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 workos/utils/um_provider_types.py diff --git a/workos/resources/user_management.py b/workos/resources/user_management.py index f396af04..c0252308 100644 --- a/workos/resources/user_management.py +++ b/workos/resources/user_management.py @@ -9,9 +9,7 @@ from workos.types.user_management.invitation_common import InvitationCommon from workos.types.user_management.magic_auth_common import MagicAuthCommon from workos.types.user_management.password_reset_common import PasswordResetCommon - - -PasswordHashType = Literal["bcrypt", "firebase-scrypt", "ssha"] +from workos.user_management import OrganizationMembershipStatus AuthenticationMethod = Literal[ "SSO", @@ -87,9 +85,6 @@ class OrganizationMembershipRole(TypedDict): slug: str -OrganizationMembershipStatus = Literal["active", "inactive", "pending"] - - class OrganizationMembership(WorkOSModel): """Representation of an WorkOS Organization Membership.""" diff --git a/workos/user_management.py b/workos/user_management.py index 37784379..1d225eea 100644 --- a/workos/user_management.py +++ b/workos/user_management.py @@ -1,4 +1,4 @@ -from typing import Optional, Protocol, Set, Union +from typing import Literal, Optional, Protocol, Set, Union import workos from workos.resources.list import ( @@ -19,15 +19,12 @@ Invitation, MagicAuth, OrganizationMembership, - OrganizationMembershipStatus, - PasswordHashType, PasswordReset, RefreshTokenAuthenticationResponse, User, ) from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.pagination_order import PaginationOrder -from workos.utils.um_provider_types import UserManagementProviderType from workos.utils.request_helper import ( DEFAULT_LIST_RESPONSE_LIMIT, RESPONSE_TYPE_CODE, @@ -68,6 +65,13 @@ PASSWORD_RESET_DETAIL_PATH = "user_management/password_reset/{0}" +PasswordHashType = Literal["bcrypt", "firebase-scrypt", "ssha"] +OrganizationMembershipStatus = Literal["active", "inactive", "pending"] +UserManagementProviderType = Literal[ + "authkit", "AppleOAuth", "GitHubOAuth", "GoogleOAuth", "MicrosoftOAuth" +] + + class UsersListFilters(ListArgs, total=False): email: Optional[str] organization_id: Optional[str] diff --git a/workos/utils/um_provider_types.py b/workos/utils/um_provider_types.py deleted file mode 100644 index 6451221b..00000000 --- a/workos/utils/um_provider_types.py +++ /dev/null @@ -1,6 +0,0 @@ -from typing import Literal - - -UserManagementProviderType = Literal[ - "authkit", "AppleOAuth", "GitHubOAuth", "GoogleOAuth", "MicrosoftOAuth" -] From 225cb37db5631459181b0671467211c29b86277c Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:52:48 -0700 Subject: [PATCH 6/8] Fix some ciruclar dependencies --- tests/test_audit_logs.py | 3 +- tests/test_sso.py | 4 +- workos/events.py | 46 +------------------ workos/resources/audit_logs.py | 4 +- workos/resources/events.py | 44 +++++++++++++++++- workos/resources/list.py | 2 +- workos/resources/passwordless.py | 2 - workos/resources/sso.py | 3 +- workos/resources/user_management.py | 4 +- workos/sso.py | 43 +++-------------- .../connection_payload_with_legacy_fields.py | 1 - workos/types/sso/connection.py | 39 +++++++++++++++- workos/user_management.py | 2 +- 13 files changed, 97 insertions(+), 100 deletions(-) diff --git a/tests/test_audit_logs.py b/tests/test_audit_logs.py index 45e359f8..9e193769 100644 --- a/tests/test_audit_logs.py +++ b/tests/test_audit_logs.py @@ -2,9 +2,8 @@ import pytest -from workos.audit_logs import AuditLogs +from workos.audit_logs import AuditLogEvent, AuditLogs from workos.exceptions import AuthenticationException, BadRequestException -from workos.resources.audit_logs import AuditLogEvent from workos.utils.http_client import SyncHTTPClient diff --git a/tests/test_sso.py b/tests/test_sso.py index 7376deba..7f8aff78 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -6,8 +6,8 @@ from tests.utils.fixtures.mock_profile import MockProfile from tests.utils.list_resource import list_data_to_dicts, list_response_of import workos -from workos.sso import SSO, AsyncSSO -from workos.resources.sso import Profile, SsoProviderType +from workos.sso import SSO, AsyncSSO, SsoProviderType +from workos.resources.sso import Profile from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.request_helper import RESPONSE_TYPE_CODE from tests.utils.fixtures.mock_connection import MockConnection diff --git a/workos/events.py b/workos/events.py index 5954608c..fc491161 100644 --- a/workos/events.py +++ b/workos/events.py @@ -3,7 +3,7 @@ import workos from workos.typing.sync_or_async import SyncOrAsync from workos.utils.request_helper import DEFAULT_LIST_RESPONSE_LIMIT, REQUEST_METHOD_GET -from workos.resources.events import Event +from workos.resources.events import Event, EventType from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.validation import EVENTS_MODULE, validate_settings from workos.resources.list import ( @@ -15,50 +15,6 @@ ) -EventType = Literal[ - "authentication.email_verification_succeeded", - "authentication.magic_auth_failed", - "authentication.magic_auth_succeeded", - "authentication.mfa_succeeded", - "authentication.oauth_succeeded", - "authentication.password_failed", - "authentication.password_succeeded", - "authentication.sso_succeeded", - "connection.activated", - "connection.deactivated", - "connection.deleted", - "dsync.activated", - "dsync.deleted", - "dsync.group.created", - "dsync.group.deleted", - "dsync.group.updated", - "dsync.user.created", - "dsync.user.deleted", - "dsync.user.updated", - "dsync.group.user_added", - "dsync.group.user_removed", - "email_verification.created", - "invitation.created", - "magic_auth.created", - "organization.created", - "organization.deleted", - "organization.updated", - "organization_domain.verification_failed", - "organization_domain.verified", - "organization_membership.created", - "organization_membership.deleted", - "organization_membership.updated", - "password_reset.created", - "role.created", - "role.deleted", - "role.updated", - "session.created", - "user.created", - "user.deleted", - "user.updated", -] - - class EventsListFilters(ListArgs, total=False): events: Sequence[EventType] organization_id: Optional[str] diff --git a/workos/resources/audit_logs.py b/workos/resources/audit_logs.py index f37d9874..75f1ec04 100644 --- a/workos/resources/audit_logs.py +++ b/workos/resources/audit_logs.py @@ -1,6 +1,4 @@ -from typing import Literal, Optional, Sequence, TypedDict -from typing_extensions import NotRequired - +from typing import Literal, Optional from workos.resources.workos_model import WorkOSModel AuditLogExportState = Literal["error", "pending", "ready"] diff --git a/workos/resources/events.py b/workos/resources/events.py index 2ed195ce..f29e6349 100644 --- a/workos/resources/events.py +++ b/workos/resources/events.py @@ -1,7 +1,6 @@ from typing import Generic, Literal, TypeVar, Union from typing_extensions import Annotated from pydantic import Field -from workos.events import EventType from workos.resources.directory_sync import DirectoryGroup from workos.resources.user_management import OrganizationMembership, User from workos.resources.workos_model import WorkOSModel @@ -47,6 +46,49 @@ from workos.types.user_management.magic_auth_common import MagicAuthCommon from workos.types.user_management.password_reset_common import PasswordResetCommon +EventType = Literal[ + "authentication.email_verification_succeeded", + "authentication.magic_auth_failed", + "authentication.magic_auth_succeeded", + "authentication.mfa_succeeded", + "authentication.oauth_succeeded", + "authentication.password_failed", + "authentication.password_succeeded", + "authentication.sso_succeeded", + "connection.activated", + "connection.deactivated", + "connection.deleted", + "dsync.activated", + "dsync.deleted", + "dsync.group.created", + "dsync.group.deleted", + "dsync.group.updated", + "dsync.user.created", + "dsync.user.deleted", + "dsync.user.updated", + "dsync.group.user_added", + "dsync.group.user_removed", + "email_verification.created", + "invitation.created", + "magic_auth.created", + "organization.created", + "organization.deleted", + "organization.updated", + "organization_domain.verification_failed", + "organization_domain.verified", + "organization_membership.created", + "organization_membership.deleted", + "organization_membership.updated", + "password_reset.created", + "role.created", + "role.deleted", + "role.updated", + "session.created", + "user.created", + "user.deleted", + "user.updated", +] + EventTypeDiscriminator = TypeVar("EventTypeDiscriminator", bound=EventType) EventPayload = TypeVar( "EventPayload", diff --git a/workos/resources/list.py b/workos/resources/list.py index 6a16071c..8ddbf195 100644 --- a/workos/resources/list.py +++ b/workos/resources/list.py @@ -1,4 +1,5 @@ import abc +from pydantic import BaseModel, Field from typing import ( AsyncIterator, Awaitable, @@ -22,7 +23,6 @@ from workos.resources.events import Event from workos.resources.mfa import AuthenticationFactor from workos.resources.organizations import Organization -from pydantic import BaseModel, Field from workos.resources.sso import ConnectionWithDomains from workos.resources.user_management import Invitation, OrganizationMembership, User from workos.resources.workos_model import WorkOSModel diff --git a/workos/resources/passwordless.py b/workos/resources/passwordless.py index 8afd48ec..788eb9d1 100644 --- a/workos/resources/passwordless.py +++ b/workos/resources/passwordless.py @@ -1,8 +1,6 @@ from typing import Literal from workos.resources.workos_model import WorkOSModel -PasswordlessSessionType = Literal["MagicLink"] - class PasswordlessSession(WorkOSModel): """Representation of a WorkOS Passwordless Session Response.""" diff --git a/workos/resources/sso.py b/workos/resources/sso.py index b5b2527e..eef4211e 100644 --- a/workos/resources/sso.py +++ b/workos/resources/sso.py @@ -1,7 +1,6 @@ from typing import Literal, Sequence, Union from workos.resources.workos_model import WorkOSModel -from workos.sso import ConnectionType -from workos.types.sso.connection import Connection +from workos.types.sso.connection import Connection, ConnectionType from workos.typing.literals import LiteralOrUntyped diff --git a/workos/resources/user_management.py b/workos/resources/user_management.py index c0252308..f78ed126 100644 --- a/workos/resources/user_management.py +++ b/workos/resources/user_management.py @@ -9,7 +9,9 @@ from workos.types.user_management.invitation_common import InvitationCommon from workos.types.user_management.magic_auth_common import MagicAuthCommon from workos.types.user_management.password_reset_common import PasswordResetCommon -from workos.user_management import OrganizationMembershipStatus + + +OrganizationMembershipStatus = Literal["active", "inactive", "pending"] AuthenticationMethod = Literal[ "SSO", diff --git a/workos/sso.py b/workos/sso.py index 71242617..fc789348 100644 --- a/workos/sso.py +++ b/workos/sso.py @@ -3,7 +3,12 @@ from workos.typing.sync_or_async import SyncOrAsync from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient from workos.utils.pagination_order import PaginationOrder -from workos.resources.sso import ConnectionWithDomains, Profile, ProfileAndToken +from workos.resources.sso import ( + ConnectionType, + ConnectionWithDomains, + Profile, + ProfileAndToken, +) from workos.utils.request_helper import ( DEFAULT_LIST_RESPONSE_LIMIT, RESPONSE_TYPE_CODE, @@ -27,42 +32,6 @@ PROFILE_PATH = "sso/profile" OAUTH_GRANT_TYPE = "authorization_code" -ConnectionType = Literal[ - "ADFSSAML", - "AdpOidc", - "AppleOAuth", - "Auth0SAML", - "AzureSAML", - "CasSAML", - "CloudflareSAML", - "ClassLinkSAML", - "CyberArkSAML", - "DuoSAML", - "GenericOIDC", - "GenericSAML", - "GitHubOAuth", - "GoogleOAuth", - "GoogleSAML", - "JumpCloudSAML", - "KeycloakSAML", - "LastPassSAML", - "LoginGovOidc", - "MagicLink", - "MicrosoftOAuth", - "MiniOrangeSAML", - "NetIqSAML", - "OktaSAML", - "OneLoginSAML", - "OracleSAML", - "PingFederateSAML", - "PingOneSAML", - "RipplingSAML", - "SalesforceSAML", - "ShibbolethGenericSAML", - "ShibbolethSAML", - "SimpleSamlPhpSAML", - "VMwareSAML", -] SsoProviderType = Literal[ "AppleOAuth", diff --git a/workos/types/events/connection_payload_with_legacy_fields.py b/workos/types/events/connection_payload_with_legacy_fields.py index a3d48e01..b443c61c 100644 --- a/workos/types/events/connection_payload_with_legacy_fields.py +++ b/workos/types/events/connection_payload_with_legacy_fields.py @@ -1,4 +1,3 @@ -from typing import Literal from workos.resources.sso import ConnectionWithDomains diff --git a/workos/types/sso/connection.py b/workos/types/sso/connection.py index 38baba68..e8f2fba5 100644 --- a/workos/types/sso/connection.py +++ b/workos/types/sso/connection.py @@ -1,13 +1,48 @@ from typing import Literal - from workos.resources.workos_model import WorkOSModel from workos.typing.literals import LiteralOrUntyped -from workos.utils.connection_types import ConnectionType ConnectionState = Literal[ "active", "deleting", "inactive", "requires_type", "validating" ] +ConnectionType = Literal[ + "ADFSSAML", + "AdpOidc", + "AppleOAuth", + "Auth0SAML", + "AzureSAML", + "CasSAML", + "CloudflareSAML", + "ClassLinkSAML", + "CyberArkSAML", + "DuoSAML", + "GenericOIDC", + "GenericSAML", + "GitHubOAuth", + "GoogleOAuth", + "GoogleSAML", + "JumpCloudSAML", + "KeycloakSAML", + "LastPassSAML", + "LoginGovOidc", + "MagicLink", + "MicrosoftOAuth", + "MiniOrangeSAML", + "NetIqSAML", + "OktaSAML", + "OneLoginSAML", + "OracleSAML", + "PingFederateSAML", + "PingOneSAML", + "RipplingSAML", + "SalesforceSAML", + "ShibbolethGenericSAML", + "ShibbolethSAML", + "SimpleSamlPhpSAML", + "VMwareSAML", +] + class Connection(WorkOSModel): object: Literal["connection"] diff --git a/workos/user_management.py b/workos/user_management.py index 1d225eea..cbf19bb5 100644 --- a/workos/user_management.py +++ b/workos/user_management.py @@ -19,6 +19,7 @@ Invitation, MagicAuth, OrganizationMembership, + OrganizationMembershipStatus, PasswordReset, RefreshTokenAuthenticationResponse, User, @@ -66,7 +67,6 @@ PasswordHashType = Literal["bcrypt", "firebase-scrypt", "ssha"] -OrganizationMembershipStatus = Literal["active", "inactive", "pending"] UserManagementProviderType = Literal[ "authkit", "AppleOAuth", "GitHubOAuth", "GoogleOAuth", "MicrosoftOAuth" ] From 52a2adf43060c127e0b2fb3a4fcda220e28fcfc8 Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 16:54:49 -0700 Subject: [PATCH 7/8] Remove empty lines --- tests/test_client.py | 1 - tests/test_sso.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 0d2b61af..cd3e6661 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,4 @@ import pytest - from workos import async_client, client from workos.exceptions import ConfigurationException diff --git a/tests/test_sso.py b/tests/test_sso.py index 7f8aff78..51845f01 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -1,8 +1,6 @@ import json - from six.moves.urllib.parse import parse_qsl, urlparse import pytest - from tests.utils.fixtures.mock_profile import MockProfile from tests.utils.list_resource import list_data_to_dicts, list_response_of import workos From dbe806de2345e5a59482509687a1b3b26ff24f16 Mon Sep 17 00:00:00 2001 From: Peter Arzhintar Date: Fri, 2 Aug 2024 17:08:27 -0700 Subject: [PATCH 8/8] Update NotRequired import --- workos/audit_logs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workos/audit_logs.py b/workos/audit_logs.py index 1828c919..35029a9f 100644 --- a/workos/audit_logs.py +++ b/workos/audit_logs.py @@ -1,5 +1,5 @@ -from typing import NotRequired, Optional, Protocol, Sequence -from typing_extensions import TypedDict +from typing import Optional, Protocol, Sequence +from typing_extensions import TypedDict, NotRequired import workos from workos.resources.audit_logs import AuditLogExport