You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`@auth0/auth0-api-js` - Server-side API security (Node.js equivalent of this library)
38
+
-`@auth0/auth0-server-js` - Server-side web app authentication (session management)
39
+
31
40
## Getting Started
32
41
33
42
### 1. Install the SDK
@@ -113,6 +122,95 @@ asyncio.run(main())
113
122
114
123
More info https://auth0.com/docs/secure/tokens/token-vault
115
124
125
+
### 5. Custom Token Exchange (Early Access)
126
+
127
+
> [!NOTE]
128
+
> This feature is currently available in [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access) for Enterprise customers. Please reach out to Auth0 support to get it enabled for your tenant.
129
+
130
+
This feature requires a [confidential client](https://auth0.com/docs/get-started/applications/confidential-and-public-applications#confidential-applications) (both `client_id` and `client_secret` must be configured).
131
+
132
+
Custom Token Exchange allows you to exchange a subject token for Auth0 tokens using RFC 8693. This is useful for:
133
+
- Getting Auth0 tokens for another audience
134
+
- Integrating external identity providers
135
+
- Migrating to Auth0
136
+
137
+
```python
138
+
import asyncio
139
+
140
+
from auth0_api_python import ApiClient, ApiClientOptions
141
+
142
+
asyncdefmain():
143
+
api_client = ApiClient(ApiClientOptions(
144
+
domain="<AUTH0_DOMAIN>",
145
+
audience="<AUTH0_AUDIENCE>",
146
+
client_id="<AUTH0_CLIENT_ID>",
147
+
client_secret="<AUTH0_CLIENT_SECRET>",
148
+
timeout=10.0# Optional: HTTP timeout in seconds (default: 10.0)
149
+
))
150
+
151
+
subject_token ="..."# Token from your legacy system or external source
152
+
153
+
result =await api_client.get_token_by_exchange_profile(
154
+
subject_token=subject_token,
155
+
subject_token_type="urn:example:subject-token",
156
+
audience="https://api.example.com", # Optional - omit if your Action or tenant configuration sets the audience
# Result contains access_token, expires_in, expires_at
162
+
# id_token, refresh_token, and scope are profile/Action dependent (not guaranteed; scope may be empty)
163
+
164
+
asyncio.run(main())
165
+
```
166
+
167
+
**Important:**
168
+
- Client authentication is sent via HTTP Basic (`client_id`/`client_secret`), not in the form body.
169
+
- Do not prefix `subject_token` with "Bearer " - send the raw token value only (checked case-insensitively).
170
+
- The `subject_token_type` must match a Token Exchange Profile configured in Auth0. This URI identifies which profile will process the exchange and **must not use reserved OAuth namespaces (IETF or vendor-controlled)**. Use your own collision-resistant namespace. See the [Custom Token Exchange documentation](https://auth0.com/docs/authenticate/custom-token-exchange) for naming guidance.
171
+
- If neither an explicit `audience` nor tenant/Action logic sets it, you may receive a token not targeted at your API.
172
+
173
+
#### Additional Parameters
174
+
175
+
You can pass additional parameters for your Token Exchange Profile or Actions via the `extra` parameter. These are sent as form fields to Auth0 and may be inspected by Actions:
176
+
177
+
```python
178
+
result =await api_client.get_token_by_exchange_profile(
179
+
subject_token=subject_token,
180
+
subject_token_type="urn:example:subject-token",
181
+
audience="https://api.example.com",
182
+
extra={
183
+
"device_id": "device-12345",
184
+
"session_id": "sess-abc"
185
+
}
186
+
)
187
+
```
188
+
189
+
> [!WARNING]
190
+
> Extra parameters are sent as form fields and may appear in logs. Do not include secrets or sensitive data. Reserved OAuth parameter names (like `grant_type`, `client_id`, `scope`) cannot be used and will raise an error. Arrays are supported but limited to 20 values per key to prevent abuse.
191
+
192
+
#### Error Handling
193
+
194
+
```python
195
+
from auth0_api_python import GetTokenByExchangeProfileError, ApiError
196
+
197
+
try:
198
+
result =await api_client.get_token_by_exchange_profile(
If the token lacks `my_custom_claim` or fails any standard check (issuer mismatch, expired token, invalid signature), the method raises a `VerifyAccessTokenError`.
128
226
129
-
### 5. DPoP Authentication
227
+
### 6. DPoP Authentication
130
228
131
229
> [!NOTE]
132
230
> 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.
0 commit comments