Skip to content

Commit

Permalink
added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zopyx committed Jul 8, 2024
1 parent 8b298be commit 7198c37
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fastapi_auth/demo_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def admin(user: User = Depends(Protected(required_roles=[ADMIN_ROLE]))):
return {"user": user}


# This is an endpoint that requires the user to be authenticated. In this case,
# the user must have the VIEW_PERMISSION permission. It is also possible to require a
# role instead. Use the Protected dependency to require authentication.
@app.get("/admin2")
def admin2(user: User = Depends(Protected(required_permission=VIEW_PERMISSION))):
return {"user": user}
Expand All @@ -111,6 +114,8 @@ def username_must_be_admin(user: User, request: Request) -> bool:
return user.name == "admin"


# This is an endpoint that requires the user to be authenticated. In this case,
# the user must have the username "admin".
@app.get("/admin3")
def admin3(user: User = Depends(Protected(required_checker=username_must_be_admin))):
return {"user": user}

0 comments on commit 7198c37

Please sign in to comment.