|
| 1 | +package workos_errors |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/workos/workos-go/v4/pkg/common" |
| 5 | +) |
| 6 | + |
| 7 | +// Authentication error code constants |
| 8 | +const ( |
| 9 | + EmailVerificationRequiredCode = "email_verification_required" |
| 10 | + MFAEnrollmentCode = "mfa_enrollment" |
| 11 | + MFAChallengeCode = "mfa_challenge" |
| 12 | + OrganizationSelectionRequiredCode = "organization_selection_required" |
| 13 | + SSORequiredCode = "sso_required" |
| 14 | + OrganizationAuthenticationMethodsRequiredCode = "organization_authentication_methods_required" |
| 15 | +) |
| 16 | + |
| 17 | +// FactorType represents the type of Authentication Factor |
| 18 | +type FactorType string |
| 19 | + |
| 20 | +// Constants that enumerate the available Types (matching mfa.FactorType) |
| 21 | +const ( |
| 22 | + SMS FactorType = "sms" |
| 23 | + TOTP FactorType = "totp" |
| 24 | +) |
| 25 | + |
| 26 | +// AuthenticationFactor represents an MFA factor |
| 27 | +type AuthenticationFactor struct { |
| 28 | + ID string `json:"id"` |
| 29 | + Type FactorType `json:"type"` |
| 30 | +} |
| 31 | + |
| 32 | +// PendingAuthenticationOrganizationInfo represents an organization in selection error |
| 33 | +type PendingAuthenticationOrganizationInfo struct { |
| 34 | + ID string `json:"id"` |
| 35 | + Name string `json:"name"` |
| 36 | +} |
| 37 | + |
| 38 | +// User is an alias for common.User to maintain consistency |
| 39 | +type User = common.User |
| 40 | + |
| 41 | +// EmailVerificationRequiredError occurs when a user with unverified email attempts authentication |
| 42 | +type EmailVerificationRequiredError struct { |
| 43 | + HTTPError |
| 44 | + Code string `json:"code"` |
| 45 | + Message string `json:"message"` |
| 46 | + Email string `json:"email"` |
| 47 | + EmailVerificationID string `json:"email_verification_id"` |
| 48 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 49 | +} |
| 50 | + |
| 51 | +func (e EmailVerificationRequiredError) Error() string { |
| 52 | + return e.HTTPError.Error() |
| 53 | +} |
| 54 | + |
| 55 | +// MFAEnrollmentError occurs when a user needs to enroll in MFA |
| 56 | +type MFAEnrollmentError struct { |
| 57 | + HTTPError |
| 58 | + Code string `json:"code"` |
| 59 | + Message string `json:"message"` |
| 60 | + User User `json:"user"` |
| 61 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 62 | +} |
| 63 | + |
| 64 | +func (e MFAEnrollmentError) Error() string { |
| 65 | + return e.HTTPError.Error() |
| 66 | +} |
| 67 | + |
| 68 | +// MFAChallengeError occurs when a user needs to complete MFA challenge |
| 69 | +type MFAChallengeError struct { |
| 70 | + HTTPError |
| 71 | + Code string `json:"code"` |
| 72 | + Message string `json:"message"` |
| 73 | + User User `json:"user"` |
| 74 | + AuthenticationFactors []AuthenticationFactor `json:"authentication_factors"` |
| 75 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 76 | +} |
| 77 | + |
| 78 | +func (e MFAChallengeError) Error() string { |
| 79 | + return e.HTTPError.Error() |
| 80 | +} |
| 81 | + |
| 82 | +// OrganizationSelectionRequiredError occurs when user must choose an organization |
| 83 | +type OrganizationSelectionRequiredError struct { |
| 84 | + HTTPError |
| 85 | + Code string `json:"code"` |
| 86 | + Message string `json:"message"` |
| 87 | + User User `json:"user"` |
| 88 | + Organizations []PendingAuthenticationOrganizationInfo `json:"organizations"` |
| 89 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 90 | +} |
| 91 | + |
| 92 | +func (e OrganizationSelectionRequiredError) Error() string { |
| 93 | + return e.HTTPError.Error() |
| 94 | +} |
| 95 | + |
| 96 | +// SSORequiredError occurs when user must authenticate via SSO |
| 97 | +type SSORequiredError struct { |
| 98 | + HTTPError |
| 99 | + ErrorCode string `json:"error"` |
| 100 | + ErrorDescription string `json:"error_description"` |
| 101 | + Email string `json:"email"` |
| 102 | + ConnectionIDs []string `json:"connection_ids"` |
| 103 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 104 | +} |
| 105 | + |
| 106 | +func (e SSORequiredError) Error() string { |
| 107 | + return e.HTTPError.Error() |
| 108 | +} |
| 109 | + |
| 110 | +// OrganizationAuthenticationMethodsRequiredError occurs when org restricts auth methods |
| 111 | +type OrganizationAuthenticationMethodsRequiredError struct { |
| 112 | + HTTPError |
| 113 | + ErrorCode string `json:"error"` |
| 114 | + ErrorDescription string `json:"error_description"` |
| 115 | + Email string `json:"email"` |
| 116 | + SSOConnectionIDs []string `json:"sso_connection_ids"` |
| 117 | + AuthMethods map[string]bool `json:"auth_methods"` |
| 118 | + PendingAuthenticationToken string `json:"pending_authentication_token"` |
| 119 | +} |
| 120 | + |
| 121 | +func (e OrganizationAuthenticationMethodsRequiredError) Error() string { |
| 122 | + return e.HTTPError.Error() |
| 123 | +} |
0 commit comments