From e8bb412e046a70628f9930972ddb99f97f0b256d Mon Sep 17 00:00:00 2001 From: Ameesha Isaac Date: Tue, 9 Jul 2024 13:54:46 -0400 Subject: [PATCH] auth and connection event types --- workos/event_objects/authentication.py | 171 +++++++++++++++++++++++++ workos/event_objects/connection.py | 95 ++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 workos/event_objects/authentication.py create mode 100644 workos/event_objects/connection.py diff --git a/workos/event_objects/authentication.py b/workos/event_objects/authentication.py new file mode 100644 index 00000000..5fa0a954 --- /dev/null +++ b/workos/event_objects/authentication.py @@ -0,0 +1,171 @@ +from typing import List, Literal, NamedTuple +from enum import Enum +from workos.utils.types import JsonDict + + +class AuthenticationType(Enum): + EMAIL_VERIFICATION = "email_verification" + MAGIC_AUTH = "magic_auth" + MFA = "mfa" + OAUTH = "oauth" + PASSWORD = "password" + SSO = "sso" + + +class Error(NamedTuple): + code: str + message: str + + +class AuthenticationFailedFields: + def __init__(self, attributes: JsonDict) -> None: + self.type: AuthenticationType = AuthenticationType(attributes["type"]) + self.status: str = attributes["status"] + self.user_id: str = attributes["user_id"] + self.email: str = attributes["email"] + self.ip_address: str = attributes["ip_address"] + self.user_agent: str = attributes["user_agent"] + self.error: Error = Error(code=attributes["error"]["code"], message=attributes["error"]["message"]) + +class AuthenticationSucceededFields: + def __init__(self, attributes: JsonDict) -> None: + self.type: AuthenticationType = AuthenticationType(attributes["type"]) + self.status: str = attributes["status"] + self.user_id: str = attributes["user_id"] + self.email: str = attributes["email"] + self.ip_address: str = attributes["ip_address"] + self.user_agent: str = attributes["user_agent"] + +class AuthenticationEmailVerificationFailedEvent: + event_name: str = "authentication.email_verification_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.email_verification_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationEmailVerificationSucceededEvent: + event_name: str = "authentication.email_verification_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.email_verification_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + +class AuthenticationMagicAuthFailedEvent: + event_name: str = "authentication.magic_auth_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.magic_auth_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationMagicAuthSucceededEvent: + event_name: str = "authentication.magic_auth_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.magic_auth_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + +class AuthenticationMFAFailedEvent: + event_name: str = "authentication.mfa_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.mfa_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationMFASucceededEvent: + event_name: str = "authentication.mfa_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.mfa_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + +class AuthenticationOAuthFailedEvent: + event_name: str = "authentication.oauth_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.oauth_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationOAuthSucceededEvent: + event_name: str = "authentication.oauth_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.oauth_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + +class AuthenticationPasswordFailedEvent: + event_name: str = "authentication.password_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.password_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationPasswordSucceededEvent: + event_name: str = "authentication.password_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.password_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + + +class AuthenticationSSOFailedEvent: + event_name: str = "authentication.sso_failed" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.sso_failed"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationFailedFields = AuthenticationFailedFields( + attributes["data"] + ) + +class AuthenticationSSOSucceededEvent: + event_name: str = "authentication.sso_succeeded" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal["authentication.sso_succeeded"] = attributes['event'] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: AuthenticationSucceededFields = AuthenticationSucceededFields( + attributes["data"] + ) + diff --git a/workos/event_objects/connection.py b/workos/event_objects/connection.py new file mode 100644 index 00000000..405959c4 --- /dev/null +++ b/workos/event_objects/connection.py @@ -0,0 +1,95 @@ +from typing import List, Literal, NamedTuple +from enum import Enum +from workos.utils.types import JsonDict + +class ConnectionState(Enum): + INACTIVE = "inactive" + ACTIVE = "active" + +class ConnectionType(Enum): + ADFS_SAML = 'ADFSSAML' + ADP_OIDC = 'AdpOidc' + AUTH0_SAML = 'Auth0SAML' + AZURE_SAML = 'AzureSAML' + CAS_SAML = 'CasSAML' + CLASS_LINK_SAML = 'ClassLinkSAML' + CLOUDFLARE_SAML = 'CloudflareSAML' + CYBER_ARK_SAML = 'CyberArkSAML' + DUO_SAML = 'DuoSAML' + GENERIC_OIDC = 'GenericOIDC' + GENERIC_SAML = 'GenericSAML' + GOOGLE_OAUTH = 'GoogleOAuth' + GOOGLE_SAML = 'GoogleSAML' + JUMP_CLOUD_SAML = 'JumpCloudSAML' + KEYCLOAK_SAML = 'KeycloakSAML' + LAST_PASS_SAML = 'LastPassSAML' + LOGIN_GOV_OIDC = 'LoginGovOidc' + MAGIC_LINK = 'MagicLink' + MICROSOFT_OAUTH = 'MicrosoftOAuth' + MINI_ORANGE_SAML = 'MiniOrangeSAML' + NET_IQ_SAML = 'NetIqSAML' + OKTA_SAML = 'OktaSAML' + ONE_LOGIN_SAML ='OneLoginSAML' + ORACLE_SAML = 'OracleSAML' + PING_FEDERATE_SAML = 'PingFederateSAML' + PING_ONE_SAML = 'PingOneSAML' + RIPPLING_SAML = 'RipplingSAML' + SALESFORCE_SAML = 'SalesforceSAML' + SHIBBOLETH_GENERIC_SAML = 'ShibbolethGenericSAML' + SHIBBOLETH_SAML = 'ShibbolethSAML' + SIMPLE_SAML_PHP_SAML = 'SimpleSamlPhpSAML' + VM_WARE_SAML = 'VMwareSAML' + +class Domain: + def __init__(self, attributes: JsonDict) -> None: + self.id: str = attributes["id"] + self.object: Literal["connection_domain"] = attributes["object"] + self.domain: str = attributes["domain"] + + +class ConnectionEvent: + def __init__(self, attributes: JsonDict) -> None: + self.object: Literal["connection"] = attributes["object"] + self.id: str = attributes["id"] + self.organization_id: str = attributes["organization_id"] + self.state: str = ConnectionState(attributes["state"]) + self.connection_type: str = ConnectionType(attributes["connection_type"]) + self.name: str = attributes["name"] + self.created_at: str = attributes["created_at"] + self.updated_at: str = attributes["updated_at"] + self.domains = [] + for domain in attributes["domains"]: + self.domains.push(Domain(attributes=domain)) + +class ConnectionActivatedEvent: + event_name = "connection.activated" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal['connection.activated'] = attributes["event"] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: ConnectionEvent = ConnectionEvent( + attributes["data"] + ) + +class ConnectionDeactivatedEvent: + event_name = "connection.deactivated" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal['connection.deactivated'] = attributes["event"] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: ConnectionEvent = ConnectionEvent( + attributes["data"] + ) + +class ConnectionDeactivatedEvent: + event_name = "connection.deleted" + + def __init__(self, attributes: JsonDict) -> None: + self.event: Literal['connection.deleted'] = attributes["event"] + self.id: str = attributes["id"] + self.created_at = attributes["created_at"] + self.data: ConnectionEvent = ConnectionEvent( + attributes["data"] + )