Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed Jun 16, 2024
1 parent e543704 commit 0e4ae01
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ def admin2(user: User = Depends(Protected(required_permission=VIEW_PERMISSION)))
```

Another option is to protect a route with a custom callback method returning `True` or `False` for a given
`Request` and `User`:

```
from fastapi_auth.dependencies import Protected
def my_check(request: Request, user: User) -> bool:
# perform some checks based on request and/or user....
return True # or False
@app.get("/admin")
def admin3(user: User = Depends(Protected(required_checker=my_check))):
return {"user": user}
```

Note that the `user` object passed to the callback is either an already
authenticated users or the `ANONYMOUS_USER`. It is up to the callback to
authorize the already authenticated user based on further criteria.



## Installation of the session middleware

In order to instrumentize your application, you need call `install_middleware(app)` with your
Expand Down

0 comments on commit 0e4ae01

Please sign in to comment.