Skip to content

Implement Starlette permissions per endpoint #8249

Answered by tiangolo
szelenka asked this question in Questions
Discussion options

You must be logged in to vote

Hmm, the authentication mechanisms included in Starlette are a little bit more fixed.

For example, it is assumed that there is a user entity with two fixed attributes:

  • .is_authenticated
  • .display_name

In FastAPI, to define different permission levels you would probably use the dependency injection system (and the security system): https://fastapi.tiangolo.com/tutorial/security/get-current-user/

With that, you can do any check you need in a dependency and handle permissions directly, you don't have to communicate the approval/disapproval using a list of strings. And it also would apply for authenticating things that are not necessarily users, like third party applications.

For a more com…

Replies: 13 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants
Converted from issue

This discussion was converted from issue #104 on February 28, 2023 14:58.