-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add DPoP Support #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0a174a
feat: Add DPoP Support
kishore7snehil 54fe8ed
tests: add authentication tests
kishore7snehil b0fdfbc
refactor: move common test mocks to conftest.py and remove duplicate β¦
kishore7snehil 96aacae
refactor: move test utilities into tests directory and improve test oβ¦
kishore7snehil 5fcc91f
docs: replace Sphinx docs workflow with markdown examples and update β¦
kishore7snehil 038f611
Merge remote-tracking branch 'origin/main' into feature/dpop
kishore7snehil d82e5eb
refactor: added internal servererror execption
kishore7snehil dc53437
refactor:addressing feedbacks
kishore7snehil 589561b
refactor: remove tests from distribution
kishore7snehil 277d5ba
refactor: update test imports to use relative paths
kishore7snehil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ server.py | |
| setup.py | ||
| test.py | ||
| test-script.py | ||
| integration_test*.py | ||
| .coverage | ||
| coverage.xml | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Auth0 FastAPI-API Examples | ||
|
|
||
| This document provides examples for using the `auth0-fastapi-api` package to secure your FastAPI applications with Auth0. | ||
|
|
||
| ## Bearer Authentication | ||
|
|
||
| ```python | ||
| from fastapi import FastAPI, Depends | ||
| from fastapi_plugin.fast_api_client import Auth0FastAPI | ||
|
|
||
| app = FastAPI() | ||
| auth0 = Auth0FastAPI( | ||
| domain="your-domain.auth0.com", | ||
| audience="your-api-identifier" | ||
| ) | ||
|
|
||
| @app.get("/api/protected") | ||
| async def protected_route(claims=Depends(auth0.require_auth())): | ||
| return {"user_id": claims["sub"]} | ||
| ``` | ||
|
|
||
| ```bash | ||
| curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ | ||
| http://localhost:8000/api/protected | ||
| ``` | ||
|
|
||
| ## DPoP Authentication | ||
|
|
||
| > [!NOTE] | ||
| > DPoP is in Early Access. Contact Auth0 support to enable it. | ||
|
|
||
| **Mixed Mode (default)** - Accept both Bearer and DPoP: | ||
|
|
||
| ```python | ||
| auth0 = Auth0FastAPI( | ||
| domain="your-domain.auth0.com", | ||
| audience="your-api-identifier", | ||
| dpop_enabled=True, # Default | ||
| dpop_required=False # Default | ||
| ) | ||
| ``` | ||
|
|
||
| ```bash | ||
| # DPoP request | ||
| curl -H "Authorization: DPoP YOUR_ACCESS_TOKEN" \ | ||
| -H "DPoP: YOUR_DPOP_PROOF_JWT" \ | ||
| http://localhost:8000/api/protected | ||
| ``` | ||
|
|
||
| **DPoP Required Mode** - Reject Bearer tokens: | ||
|
|
||
| ```python | ||
| auth0 = Auth0FastAPI( | ||
| domain="your-domain.auth0.com", | ||
| audience="your-api-identifier", | ||
| dpop_required=True | ||
| ) | ||
| ``` | ||
|
|
||
| **Bearer-Only Mode** - Disable DPoP: | ||
|
|
||
| ```python | ||
| auth0 = Auth0FastAPI( | ||
| domain="your-domain.auth0.com", | ||
| audience="your-api-identifier", | ||
| dpop_enabled=False | ||
| ) | ||
| ``` | ||
|
|
||
| ## Scope Validation | ||
|
|
||
| ```python | ||
| @app.get("/api/admin") | ||
| async def admin_route(claims=Depends(auth0.require_auth(scopes=["admin:access"]))): | ||
| return {"message": "Admin access granted"} | ||
|
|
||
| @app.delete("/api/resource") | ||
| async def delete_route( | ||
| claims=Depends(auth0.require_auth(scopes=["delete:data", "admin:access"])) | ||
| ): | ||
| """Requires BOTH scopes.""" | ||
| return {"message": "Resource deleted"} | ||
| ``` | ||
|
|
||
| ## Reverse Proxy Support | ||
|
|
||
| Enable X-Forwarded-* header trust for DPoP behind proxies: | ||
|
|
||
| ```python | ||
| app = FastAPI() | ||
| app.state.trust_proxy = True # Required for load balancers/CDN | ||
|
|
||
| auth0 = Auth0FastAPI( | ||
| domain="your-domain.auth0.com", | ||
| audience="your-api-identifier" | ||
| ) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states "Allow Bearer tokens too" but the configuration shows
dpop_required=False. This might be confusing sincedpop_enabled=Trueis what enables DPoP support.Consider clarifying that this mode accepts BOTH authentication types: