-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
186 lines (146 loc) · 5.7 KB
/
__init__.py
File metadata and controls
186 lines (146 loc) · 5.7 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
"""
Error classes for the auth0-server-python SDK.
These exceptions provide specific error types for different failure scenarios.
"""
from typing import 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 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 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 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"
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"
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"