auth0-api-python 1.0.0b3__tar.gz → 1.0.0b5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {auth0_api_python-1.0.0b3 → auth0_api_python-1.0.0b5}/PKG-INFO +105 -3
- {auth0_api_python-1.0.0b3 → auth0_api_python-1.0.0b5}/README.md +103 -2
- {auth0_api_python-1.0.0b3 → auth0_api_python-1.0.0b5}/pyproject.toml +3 -2
- {auth0_api_python-1.0.0b3 → auth0_api_python-1.0.0b5}/src/auth0_api_python/__init__.py +1 -1
- auth0_api_python-1.0.0b5/src/auth0_api_python/api_client.py +663 -0
- auth0_api_python-1.0.0b5/src/auth0_api_python/config.py +43 -0
- auth0_api_python-1.0.0b5/src/auth0_api_python/errors.py +132 -0
- auth0_api_python-1.0.0b5/src/auth0_api_python/token_utils.py +221 -0
- auth0_api_python-1.0.0b5/src/auth0_api_python/utils.py +157 -0
- auth0_api_python-1.0.0b3/src/auth0_api_python/api_client.py +0 -128
- auth0_api_python-1.0.0b3/src/auth0_api_python/config.py +0 -24
- auth0_api_python-1.0.0b3/src/auth0_api_python/errors.py +0 -21
- auth0_api_python-1.0.0b3/src/auth0_api_python/token_utils.py +0 -84
- auth0_api_python-1.0.0b3/src/auth0_api_python/utils.py +0 -88
- {auth0_api_python-1.0.0b3 → auth0_api_python-1.0.0b5}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: auth0-api-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b5
|
|
4
4
|
Summary: SDK for verifying access tokens and securing APIs with Auth0, using Authlib.
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Auth0
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: ada-url (>=1.25.0,<2.0.0)
|
|
16
17
|
Requires-Dist: authlib (>=1.0,<2.0)
|
|
17
18
|
Requires-Dist: httpx (>=0.28.1,<0.29.0)
|
|
18
19
|
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
@@ -26,6 +27,24 @@ It’s intended as a foundation for building more framework-specific integration
|
|
|
26
27
|
|
|
27
28
|
📚 [Documentation](#documentation) - 🚀 [Getting Started](#getting-started) - 💬 [Feedback](#feedback)
|
|
28
29
|
|
|
30
|
+
## Features & Authentication Schemes
|
|
31
|
+
|
|
32
|
+
This SDK provides comprehensive support for securing APIs with Auth0-issued access tokens:
|
|
33
|
+
|
|
34
|
+
### **Authentication Schemes**
|
|
35
|
+
- **Bearer Token Authentication** - Traditional OAuth 2.0 Bearer tokens (RS256)
|
|
36
|
+
- **DPoP Authentication** - Enhanced security with Demonstrating Proof-of-Possession (ES256)
|
|
37
|
+
- **Mixed Mode Support** - Seamlessly handles both Bearer and DPoP in the same API
|
|
38
|
+
|
|
39
|
+
### **Core Features**
|
|
40
|
+
- **Unified Entry Point**: `verify_request()` - automatically detects and validates Bearer or DPoP schemes
|
|
41
|
+
- **OIDC Discovery** - Automatic fetching of Auth0 metadata and JWKS
|
|
42
|
+
- **JWT Validation** - Complete RS256 signature verification with claim validation
|
|
43
|
+
- **DPoP Proof Verification** - Full RFC 9449 compliance with ES256 signature validation
|
|
44
|
+
- **Flexible Configuration** - Support for both "Allowed" and "Required" DPoP modes
|
|
45
|
+
- **Comprehensive Error Handling** - Detailed errors with proper HTTP status codes and WWW-Authenticate headers
|
|
46
|
+
- **Framework Agnostic** - Works with FastAPI, Django, Flask, or any Python web framework
|
|
47
|
+
|
|
29
48
|
## Documentation
|
|
30
49
|
|
|
31
50
|
- [Docs Site](https://auth0.com/docs) - explore our docs site and learn more about Auth0.
|
|
@@ -87,6 +106,34 @@ asyncio.run(main())
|
|
|
87
106
|
|
|
88
107
|
In this example, the returned dictionary contains the decoded claims (like `sub`, `scope`, etc.) from the verified token.
|
|
89
108
|
|
|
109
|
+
### 4. Get an access token for a connection
|
|
110
|
+
|
|
111
|
+
If you need to get an access token for an upstream idp via a connection, you can use the `get_access_token_for_connection` method:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
|
|
116
|
+
from auth0_api_python import ApiClient, ApiClientOptions
|
|
117
|
+
|
|
118
|
+
async def main():
|
|
119
|
+
api_client = ApiClient(ApiClientOptions(
|
|
120
|
+
domain="<AUTH0_DOMAIN>",
|
|
121
|
+
audience="<AUTH0_AUDIENCE>",
|
|
122
|
+
client_id="<AUTH0_CLIENT_ID>",
|
|
123
|
+
client_secret="<AUTH0_CLIENT_SECRET>",
|
|
124
|
+
))
|
|
125
|
+
connection = "my-connection" # The Auth0 connection to the upstream idp
|
|
126
|
+
access_token = "..." # The Auth0 access token to exchange
|
|
127
|
+
|
|
128
|
+
connection_access_token = await api_client.get_access_token_for_connection({"connection": connection, "access_token": access_token})
|
|
129
|
+
# The returned token is the access token for the upstream idp
|
|
130
|
+
print(connection_access_token)
|
|
131
|
+
|
|
132
|
+
asyncio.run(main())
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
More info https://auth0.com/docs/secure/tokens/token-vault
|
|
136
|
+
|
|
90
137
|
#### Requiring Additional Claims
|
|
91
138
|
|
|
92
139
|
If your application demands extra claims, specify them with `required_claims`:
|
|
@@ -100,6 +147,61 @@ decoded_and_verified_token = await api_client.verify_access_token(
|
|
|
100
147
|
|
|
101
148
|
If the token lacks `my_custom_claim` or fails any standard check (issuer mismatch, expired token, invalid signature), the method raises a `VerifyAccessTokenError`.
|
|
102
149
|
|
|
150
|
+
### 5. DPoP Authentication
|
|
151
|
+
|
|
152
|
+
> [!NOTE]
|
|
153
|
+
> 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.
|
|
154
|
+
|
|
155
|
+
This library supports **DPoP (Demonstrating Proof-of-Possession)** for enhanced security, allowing clients to prove possession of private keys bound to access tokens.
|
|
156
|
+
|
|
157
|
+
#### Allowed Mode (Default)
|
|
158
|
+
|
|
159
|
+
Accepts both Bearer and DPoP tokens - ideal for gradual migration:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
api_client = ApiClient(ApiClientOptions(
|
|
163
|
+
domain="<AUTH0_DOMAIN>",
|
|
164
|
+
audience="<AUTH0_AUDIENCE>",
|
|
165
|
+
dpop_enabled=True, # Default - enables DPoP support
|
|
166
|
+
dpop_required=False # Default - allows both Bearer and DPoP
|
|
167
|
+
))
|
|
168
|
+
|
|
169
|
+
# Use verify_request() for automatic scheme detection
|
|
170
|
+
result = await api_client.verify_request(
|
|
171
|
+
headers={
|
|
172
|
+
"authorization": "DPoP eyJ0eXAiOiJKV1Q...", # DPoP scheme
|
|
173
|
+
"dpop": "eyJ0eXAiOiJkcG9wK2p3dC...", # DPoP proof
|
|
174
|
+
},
|
|
175
|
+
http_method="GET",
|
|
176
|
+
http_url="https://api.example.com/resource"
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Required Mode
|
|
181
|
+
|
|
182
|
+
Enforces DPoP-only authentication, rejecting Bearer tokens:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
api_client = ApiClient(ApiClientOptions(
|
|
186
|
+
domain="<AUTH0_DOMAIN>",
|
|
187
|
+
audience="<AUTH0_AUDIENCE>",
|
|
188
|
+
dpop_required=True # Rejects Bearer tokens
|
|
189
|
+
))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Configuration Options
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
api_client = ApiClient(ApiClientOptions(
|
|
196
|
+
domain="<AUTH0_DOMAIN>",
|
|
197
|
+
audience="<AUTH0_AUDIENCE>",
|
|
198
|
+
dpop_enabled=True, # Enable/disable DPoP support
|
|
199
|
+
dpop_required=False, # Require DPoP (reject Bearer)
|
|
200
|
+
dpop_iat_leeway=30, # Clock skew tolerance (seconds)
|
|
201
|
+
dpop_iat_offset=300, # Maximum proof age (seconds)
|
|
202
|
+
))
|
|
203
|
+
```
|
|
204
|
+
|
|
103
205
|
## Feedback
|
|
104
206
|
|
|
105
207
|
### Contributing
|
|
@@ -108,7 +210,7 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
|
|
|
108
210
|
|
|
109
211
|
- [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
|
|
110
212
|
- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
|
|
111
|
-
- [This repo's contribution guide](
|
|
213
|
+
- [This repo's contribution guide](https://github.com/auth0/auth0-api-python/CONTRIBUTING.md)
|
|
112
214
|
|
|
113
215
|
### Raise an issue
|
|
114
216
|
|
|
@@ -131,5 +233,5 @@ Please do not report security vulnerabilities on the public GitHub issue tracker
|
|
|
131
233
|
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a>
|
|
132
234
|
</p>
|
|
133
235
|
<p align="center">
|
|
134
|
-
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-
|
|
236
|
+
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-api-python/LICENSE"> LICENSE</a> file for more info.
|
|
135
237
|
</p>
|
|
@@ -6,6 +6,24 @@ It’s intended as a foundation for building more framework-specific integration
|
|
|
6
6
|
|
|
7
7
|
📚 [Documentation](#documentation) - 🚀 [Getting Started](#getting-started) - 💬 [Feedback](#feedback)
|
|
8
8
|
|
|
9
|
+
## Features & Authentication Schemes
|
|
10
|
+
|
|
11
|
+
This SDK provides comprehensive support for securing APIs with Auth0-issued access tokens:
|
|
12
|
+
|
|
13
|
+
### **Authentication Schemes**
|
|
14
|
+
- **Bearer Token Authentication** - Traditional OAuth 2.0 Bearer tokens (RS256)
|
|
15
|
+
- **DPoP Authentication** - Enhanced security with Demonstrating Proof-of-Possession (ES256)
|
|
16
|
+
- **Mixed Mode Support** - Seamlessly handles both Bearer and DPoP in the same API
|
|
17
|
+
|
|
18
|
+
### **Core Features**
|
|
19
|
+
- **Unified Entry Point**: `verify_request()` - automatically detects and validates Bearer or DPoP schemes
|
|
20
|
+
- **OIDC Discovery** - Automatic fetching of Auth0 metadata and JWKS
|
|
21
|
+
- **JWT Validation** - Complete RS256 signature verification with claim validation
|
|
22
|
+
- **DPoP Proof Verification** - Full RFC 9449 compliance with ES256 signature validation
|
|
23
|
+
- **Flexible Configuration** - Support for both "Allowed" and "Required" DPoP modes
|
|
24
|
+
- **Comprehensive Error Handling** - Detailed errors with proper HTTP status codes and WWW-Authenticate headers
|
|
25
|
+
- **Framework Agnostic** - Works with FastAPI, Django, Flask, or any Python web framework
|
|
26
|
+
|
|
9
27
|
## Documentation
|
|
10
28
|
|
|
11
29
|
- [Docs Site](https://auth0.com/docs) - explore our docs site and learn more about Auth0.
|
|
@@ -67,6 +85,34 @@ asyncio.run(main())
|
|
|
67
85
|
|
|
68
86
|
In this example, the returned dictionary contains the decoded claims (like `sub`, `scope`, etc.) from the verified token.
|
|
69
87
|
|
|
88
|
+
### 4. Get an access token for a connection
|
|
89
|
+
|
|
90
|
+
If you need to get an access token for an upstream idp via a connection, you can use the `get_access_token_for_connection` method:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import asyncio
|
|
94
|
+
|
|
95
|
+
from auth0_api_python import ApiClient, ApiClientOptions
|
|
96
|
+
|
|
97
|
+
async def main():
|
|
98
|
+
api_client = ApiClient(ApiClientOptions(
|
|
99
|
+
domain="<AUTH0_DOMAIN>",
|
|
100
|
+
audience="<AUTH0_AUDIENCE>",
|
|
101
|
+
client_id="<AUTH0_CLIENT_ID>",
|
|
102
|
+
client_secret="<AUTH0_CLIENT_SECRET>",
|
|
103
|
+
))
|
|
104
|
+
connection = "my-connection" # The Auth0 connection to the upstream idp
|
|
105
|
+
access_token = "..." # The Auth0 access token to exchange
|
|
106
|
+
|
|
107
|
+
connection_access_token = await api_client.get_access_token_for_connection({"connection": connection, "access_token": access_token})
|
|
108
|
+
# The returned token is the access token for the upstream idp
|
|
109
|
+
print(connection_access_token)
|
|
110
|
+
|
|
111
|
+
asyncio.run(main())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
More info https://auth0.com/docs/secure/tokens/token-vault
|
|
115
|
+
|
|
70
116
|
#### Requiring Additional Claims
|
|
71
117
|
|
|
72
118
|
If your application demands extra claims, specify them with `required_claims`:
|
|
@@ -80,6 +126,61 @@ decoded_and_verified_token = await api_client.verify_access_token(
|
|
|
80
126
|
|
|
81
127
|
If the token lacks `my_custom_claim` or fails any standard check (issuer mismatch, expired token, invalid signature), the method raises a `VerifyAccessTokenError`.
|
|
82
128
|
|
|
129
|
+
### 5. DPoP Authentication
|
|
130
|
+
|
|
131
|
+
> [!NOTE]
|
|
132
|
+
> 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.
|
|
133
|
+
|
|
134
|
+
This library supports **DPoP (Demonstrating Proof-of-Possession)** for enhanced security, allowing clients to prove possession of private keys bound to access tokens.
|
|
135
|
+
|
|
136
|
+
#### Allowed Mode (Default)
|
|
137
|
+
|
|
138
|
+
Accepts both Bearer and DPoP tokens - ideal for gradual migration:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
api_client = ApiClient(ApiClientOptions(
|
|
142
|
+
domain="<AUTH0_DOMAIN>",
|
|
143
|
+
audience="<AUTH0_AUDIENCE>",
|
|
144
|
+
dpop_enabled=True, # Default - enables DPoP support
|
|
145
|
+
dpop_required=False # Default - allows both Bearer and DPoP
|
|
146
|
+
))
|
|
147
|
+
|
|
148
|
+
# Use verify_request() for automatic scheme detection
|
|
149
|
+
result = await api_client.verify_request(
|
|
150
|
+
headers={
|
|
151
|
+
"authorization": "DPoP eyJ0eXAiOiJKV1Q...", # DPoP scheme
|
|
152
|
+
"dpop": "eyJ0eXAiOiJkcG9wK2p3dC...", # DPoP proof
|
|
153
|
+
},
|
|
154
|
+
http_method="GET",
|
|
155
|
+
http_url="https://api.example.com/resource"
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### Required Mode
|
|
160
|
+
|
|
161
|
+
Enforces DPoP-only authentication, rejecting Bearer tokens:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
api_client = ApiClient(ApiClientOptions(
|
|
165
|
+
domain="<AUTH0_DOMAIN>",
|
|
166
|
+
audience="<AUTH0_AUDIENCE>",
|
|
167
|
+
dpop_required=True # Rejects Bearer tokens
|
|
168
|
+
))
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Configuration Options
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
api_client = ApiClient(ApiClientOptions(
|
|
175
|
+
domain="<AUTH0_DOMAIN>",
|
|
176
|
+
audience="<AUTH0_AUDIENCE>",
|
|
177
|
+
dpop_enabled=True, # Enable/disable DPoP support
|
|
178
|
+
dpop_required=False, # Require DPoP (reject Bearer)
|
|
179
|
+
dpop_iat_leeway=30, # Clock skew tolerance (seconds)
|
|
180
|
+
dpop_iat_offset=300, # Maximum proof age (seconds)
|
|
181
|
+
))
|
|
182
|
+
```
|
|
183
|
+
|
|
83
184
|
## Feedback
|
|
84
185
|
|
|
85
186
|
### Contributing
|
|
@@ -88,7 +189,7 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
|
|
|
88
189
|
|
|
89
190
|
- [Auth0's general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
|
|
90
191
|
- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
|
|
91
|
-
- [This repo's contribution guide](
|
|
192
|
+
- [This repo's contribution guide](https://github.com/auth0/auth0-api-python/CONTRIBUTING.md)
|
|
92
193
|
|
|
93
194
|
### Raise an issue
|
|
94
195
|
|
|
@@ -111,5 +212,5 @@ Please do not report security vulnerabilities on the public GitHub issue tracker
|
|
|
111
212
|
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a>
|
|
112
213
|
</p>
|
|
113
214
|
<p align="center">
|
|
114
|
-
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-
|
|
215
|
+
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-api-python/LICENSE"> LICENSE</a> file for more info.
|
|
115
216
|
</p>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "auth0-api-python"
|
|
3
|
-
version = "1.0.0.
|
|
3
|
+
version = "1.0.0.b5"
|
|
4
4
|
description = "SDK for verifying access tokens and securing APIs with Auth0, using Authlib."
|
|
5
5
|
authors = ["Auth0 <support@auth0.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -15,6 +15,7 @@ python = "^3.9"
|
|
|
15
15
|
authlib = "^1.0" # For JWT/OIDC features
|
|
16
16
|
requests = "^2.31.0" # If you use requests for HTTP calls (e.g., discovery)
|
|
17
17
|
httpx = "^0.28.1"
|
|
18
|
+
ada-url = "^1.25.0"
|
|
18
19
|
|
|
19
20
|
[tool.poetry.group.dev.dependencies]
|
|
20
21
|
pytest = "^8.0"
|
|
@@ -22,7 +23,7 @@ pytest-cov = "^4.0"
|
|
|
22
23
|
pytest-asyncio = "^0.20.3"
|
|
23
24
|
pytest-mock = "^3.14.0"
|
|
24
25
|
pytest-httpx = "^0.35.0"
|
|
25
|
-
|
|
26
|
+
ruff = "^0.1.0"
|
|
26
27
|
|
|
27
28
|
[tool.pytest.ini_options]
|
|
28
29
|
addopts = "--cov=src --cov-report=term-missing:skip-covered --cov-report=xml"
|