Skip to content

Commit 8070249

Browse files
committed
Updates per PR review
1 parent 1f300a5 commit 8070249

4 files changed

Lines changed: 19 additions & 10 deletions

File tree

packages/auth0_api_python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ decoded_and_verified_token = await api_client.verify_access_token(
126126

127127
If the token lacks `my_custom_claim` or fails any standard check (issuer mismatch, expired token, invalid signature), the method raises a `VerifyAccessTokenError`.
128128

129-
### 4. DPoP Authentication
129+
### 5. DPoP Authentication
130130

131131
> [!NOTE]
132132
> This feature is currently available in [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). Please reach out to Auth0 support to get it enabled for your tenant.

packages/auth0_api_python/src/auth0_api_python/api_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ async def get_access_token_for_connection(self, options: dict[str, Any]) -> dict
460460
raise ApiError(
461461
error_data.get("error", "connection_token_error"),
462462
error_data.get(
463-
"error_description", f"Failed to get token for connection: {response.status_code}")
463+
"error_description", f"Failed to get token for connection: {response.status_code}"),
464+
response.status_code
464465
)
465466

466467
token_endpoint_response = response.json()

packages/auth0_api_python/src/auth0_api_python/errors.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,37 @@ def get_error_code(self) -> str:
9696
return "invalid_request"
9797

9898

99-
class GetAccessTokenForConnectionError(Exception):
99+
class GetAccessTokenForConnectionError(BaseAuthError):
100100
"""Error raised when getting a token for a connection fails."""
101-
code = "get_access_token_for_connection_error"
102101

103-
def __init__(self, message: str):
104-
super().__init__(message)
105-
self.name = self.__class__.__name__
102+
def get_status_code(self) -> int:
103+
return 400
106104

105+
def get_error_code(self) -> str:
106+
return "get_access_token_for_connection_error"
107107

108-
class ApiError(Exception):
108+
109+
class ApiError(BaseAuthError):
109110
"""
110111
Error raised when an API request to Auth0 fails.
111112
Contains details about the original error from Auth0.
112113
"""
113114

114-
def __init__(self, code: str, message: str, cause=None):
115+
def __init__(self, code: str, message: str, status_code=500, cause=None):
115116
super().__init__(message)
116117
self.code = code
118+
self.status_code = status_code
117119
self.cause = cause
118120

119-
# Extract additional error details if available
120121
if cause:
121122
self.error = getattr(cause, "error", None)
122123
self.error_description = getattr(cause, "error_description", None)
123124
else:
124125
self.error = None
125126
self.error_description = None
127+
128+
def get_status_code(self) -> int:
129+
return self.status_code
130+
131+
def get_error_code(self) -> str:
132+
return self.code

packages/auth0_api_python/tests/test_api_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,3 +1730,4 @@ async def test_get_access_token_for_connection_token_endpoint_error(httpx_mock:
17301730
"access_token": "user-token"
17311731
})
17321732
assert err.value.code == "invalid_request"
1733+
assert err.value.status_code == 400

0 commit comments

Comments
 (0)