-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
324 lines (246 loc) · 9.88 KB
/
Copy path__init__.py
File metadata and controls
324 lines (246 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
"""
Error classes for the auth0-server-python SDK.
These exceptions provide specific error types for different failure scenarios.
"""
from typing import Any, Optional
class Auth0Error(Exception):
"""Base class for all Auth0 SDK errors."""
def __init__(self, message=None):
self.message = message
super().__init__(message)
class MissingTransactionError(Auth0Error):
"""
Error raised when a required transaction is missing.
This typically happens during the callback phase when the transaction
from the initial authorization request cannot be found.
"""
code = "missing_transaction_error"
def __init__(self, message=None):
super().__init__(message or "The transaction is missing.")
self.name = "MissingTransactionError"
class ApiError(Auth0Error):
"""
Error raised when an API request to Auth0 fails.
Contains details about the original error from Auth0.
"""
def __init__(self, code: str, message: str, cause=None):
super().__init__(message)
self.code = code
self.cause = cause
# Extract additional error details if available
if cause:
self.error = getattr(cause, "error", None)
self.error_description = getattr(cause, "error_description", None)
else:
self.error = None
self.error_description = None
class PollingApiError(ApiError):
"""
Error raised when a polling API request to Auth0 fails.
Contains details about the original error from Auth0 and the requested polling interval.
"""
def __init__(self, code: str, message: str, interval: Optional[int], cause=None):
super().__init__(code, message, cause)
self.interval = interval
class MyAccountApiError(Auth0Error):
"""
Error raised when an API request to My Account API fails.
Contains details about the original error from Auth0.
"""
def __init__(
self,
title: Optional[str],
type: Optional[str],
detail: Optional[str],
status: Optional[int],
validation_errors: Optional[list[dict[str, str]]] = None
):
super().__init__(detail)
self.title = title
self.type = type
self.detail = detail
self.status = status
self.validation_errors = validation_errors
class AccessTokenError(Auth0Error):
"""Error raised when there's an issue with access tokens."""
def __init__(self, code: str, message: str, cause=None):
super().__init__(message)
self.code = code
self.name = "AccessTokenError"
self.cause = cause
class MissingRequiredArgumentError(Auth0Error):
"""
Error raised when a required argument is missing.
Includes the name of the missing argument in the error message.
"""
code = "missing_required_argument_error"
def __init__(self, argument: str):
message = f"The argument '{argument}' is required but was not provided."
super().__init__(message)
self.name = "MissingRequiredArgumentError"
self.argument = argument
class ConfigurationError(Auth0Error):
"""
Error raised when SDK configuration is invalid.
This includes invalid combinations of parameters or incorrect configuration values.
"""
code = "configuration_error"
def __init__(self, message: str):
super().__init__(message)
self.name = "ConfigurationError"
class InvalidArgumentError(Auth0Error):
"""
Error raised when a given argument is an invalid value.
"""
code = "invalid_argument"
def __init__(self, argument: str, message: str):
super().__init__(message)
self.name = "InvalidArgumentError"
self.argument = argument
class IssuerValidationError(Auth0Error):
"""
Error raised when token issuer validation fails.
This can happen when the issuer claim in a token does not match
the expected issuer for the configured domain.
"""
code = "issuer_validation_error"
def __init__(self, message: str):
super().__init__(message)
self.name = "IssuerValidationError"
class BackchannelLogoutError(Auth0Error):
"""
Error raised during backchannel logout processing.
This can happen when validating or processing logout tokens.
"""
code = "backchannel_logout_error"
def __init__(self, message: str):
super().__init__(message)
self.name = "BackchannelLogoutError"
class DomainResolverError(Auth0Error):
"""
Error raised when domain resolver function fails or returns invalid value.
This error indicates an issue with the custom domain resolver function
provided for MCD (Multiple Custom Domains) support.
"""
code = "domain_resolver_error"
def __init__(self, message: str, original_error: Exception = None):
super().__init__(message)
self.name = "DomainResolverError"
self.original_error = original_error
class AccessTokenForConnectionError(Auth0Error):
"""Error when retrieving access tokens for a specific connection fails."""
def __init__(self, code: str, message: str):
super().__init__(message)
self.code = code
self.name = "AccessTokenForConnectionError"
class StartLinkUserError(Auth0Error):
"""
Error raised when user linking process fails to start.
This typically happens when trying to link accounts without
having an authenticated user first.
"""
code = "start_link_user_error"
def __init__(self, message: str):
super().__init__(message)
self.name = "StartLinkUserError"
# Error code enumerations - these can be used to identify specific error scenarios
class AccessTokenErrorCode:
"""Error codes for access token operations."""
MISSING_SESSION = "missing_session"
MISSING_REFRESH_TOKEN = "missing_refresh_token"
FAILED_TO_REFRESH_TOKEN = "failed_to_refresh_token"
FAILED_TO_REQUEST_TOKEN = "failed_to_request_token"
REFRESH_TOKEN_ERROR = "refresh_token_error"
AUTH_REQ_ID_ERROR = "auth_req_id_error"
INCORRECT_AUDIENCE = "incorrect_audience"
MISSING_SESSION_DOMAIN = "missing_session_domain"
DOMAIN_MISMATCH = "domain_mismatch"
class OrganizationTokenValidationError(Auth0Error):
"""
Raised when org_id or org_name claim in the ID token fails validation
against the organization value that was requested at login.
"""
code = "organization_token_validation_error"
def __init__(self, message: str):
super().__init__(message)
self.name = "OrganizationTokenValidationError"
class AccessTokenForConnectionErrorCode:
"""Error codes for connection-specific token operations."""
MISSING_REFRESH_TOKEN = "missing_refresh_token"
FAILED_TO_RETRIEVE = "failed_to_retrieve"
API_ERROR = "api_error"
FETCH_ERROR = "retrieval_error"
MISSING_SESSION_DOMAIN = "missing_session_domain"
DOMAIN_MISMATCH = "domain_mismatch"
class CustomTokenExchangeError(Auth0Error):
"""
Error raised during custom token exchange operations.
"""
def __init__(self, code: str, message: str, cause=None):
super().__init__(message)
self.code = code
self.name = "CustomTokenExchangeError"
self.cause = cause
class CustomTokenExchangeErrorCode:
"""Error codes for custom token exchange operations."""
INVALID_TOKEN_FORMAT = "invalid_token_format"
MISSING_ACTOR_TOKEN_TYPE = "missing_actor_token_type"
TOKEN_EXCHANGE_FAILED = "token_exchange_failed"
INVALID_RESPONSE = "invalid_response"
# =============================================================================
# MFA Error Classes
# =============================================================================
class MfaApiError(Auth0Error):
"""Base class for MFA API errors."""
def __init__(
self,
code: str,
message: str,
cause: Optional[dict[str, Any]] = None
):
super().__init__(message)
self.code = code
self.cause = cause
class MfaListAuthenticatorsError(MfaApiError):
"""Error thrown when listing authenticators fails."""
def __init__(self, message: str, cause: Optional[dict] = None):
super().__init__("mfa_list_authenticators_error", message, cause)
class MfaEnrollmentError(MfaApiError):
"""Error thrown when enrolling an authenticator fails."""
def __init__(self, message: str, cause: Optional[dict] = None):
super().__init__("mfa_enrollment_error", message, cause)
class MfaChallengeError(MfaApiError):
"""Error thrown when initiating an MFA challenge fails."""
def __init__(self, message: str, cause: Optional[dict] = None):
super().__init__("mfa_challenge_error", message, cause)
class MfaVerifyError(MfaApiError):
"""Error thrown when MFA verification fails."""
def __init__(self, message: str, cause: Optional[dict] = None):
super().__init__("mfa_verify_error", message, cause)
class MfaRequiredError(AccessTokenError):
"""
Error thrown when MFA step-up is required during token refresh.
Contains an encrypted mfa_token that can be passed to MfaClient methods.
This error is raised in get_access_token() when the token endpoint returns
'mfa_required'.
"""
def __init__(
self,
message: str,
mfa_token: str,
mfa_requirements=None,
cause: Optional[Exception] = None
):
super().__init__("mfa_required", message, cause)
self.mfa_token = mfa_token
self.mfa_requirements = mfa_requirements
class MfaTokenExpiredError(Auth0Error):
"""Error thrown when the encrypted MFA token has expired."""
def __init__(self):
super().__init__("The MFA token has expired.")
self.code = "mfa_token_expired"
class MfaTokenInvalidError(Auth0Error):
"""Error thrown when the encrypted MFA token is invalid or tampered."""
def __init__(self):
super().__init__("The MFA token is invalid.")
self.code = "mfa_token_invalid"