Skip to content

Commit 0de7722

Browse files
authored
[auth0-fastapi-api] Adds example with route protection via path decorator (#17)
1 parent 6f5e5cb commit 0de7722

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/auth0_fastapi_api/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ async def custom_claims_route(claims: dict = Depends(auth0.require_auth())):
7979
```
8080
You can parse or validate these claims however you like in your application code.
8181

82+
### Dependency in the path operation decorator
83+
84+
In case you don't need to use the `claims` dictionary in your endpoint you can also use the dependency as part of the path decorator. For example:
85+
86+
```python
87+
@app.get("/protected", dependencies=Depends(auth0.require_auth()))
88+
async def protected():
89+
# Protected endpoint
90+
return {"msg": "You need to have an access token to see this endpoint."}
91+
92+
```
93+
94+
This way you can protected your endpoint and not have an unused variable.
95+
8296
### 4. Advanced Configuration
8397
- **Scopes**: If you need to check for specific scopes (like `read:data`), call r`equire_auth(scopes="read:data")` or pass a list of scopes. The SDK will return a 403 if the token lacks those scopes in its `scope` claim.
8498
```python

0 commit comments

Comments
 (0)