Skip to content

Commit 8fcf817

Browse files
docs(auth): Add examples for custom token exchange in README and new documentation file
1 parent 73cdd95 commit 8fcf817

File tree

2 files changed

+419
-0
lines changed

2 files changed

+419
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,47 @@ async def callback(request: Request):
104104
return RedirectResponse(url="/")
105105
```
106106

107+
### 4. Login with Custom Token Exchange
108+
109+
If you're migrating from a legacy authentication system or integrating with a custom identity provider, you can exchange external tokens for Auth0 tokens using the OAuth 2.0 Token Exchange specification (RFC 8693):
110+
111+
```python
112+
from auth0_server_python.auth_types import LoginWithCustomTokenExchangeOptions
113+
114+
# Exchange a custom token and establish a session
115+
result = await auth0.login_with_custom_token_exchange(
116+
LoginWithCustomTokenExchangeOptions(
117+
subject_token="your-custom-token",
118+
subject_token_type="urn:acme:mcp-token",
119+
audience="https://api.example.com"
120+
),
121+
store_options={"request": request, "response": response}
122+
)
123+
124+
# Access the user session
125+
user = result.state_data["user"]
126+
```
127+
128+
For advanced token exchange scenarios (without creating a session), use `custom_token_exchange()` directly:
129+
130+
```python
131+
from auth0_server_python.auth_types import CustomTokenExchangeOptions
132+
133+
# Exchange a custom token for Auth0 tokens
134+
response = await auth0.custom_token_exchange(
135+
CustomTokenExchangeOptions(
136+
subject_token="your-custom-token",
137+
subject_token_type="urn:acme:mcp-token",
138+
audience="https://api.example.com",
139+
scope="read:data write:data"
140+
)
141+
)
142+
143+
print(response.access_token)
144+
```
145+
146+
For more details and examples, see [examples/CustomTokenExchange.md](examples/CustomTokenExchange.md).
147+
107148
## Feedback
108149

109150
### Contributing

0 commit comments

Comments
 (0)