# Who May Do What

Knowing who someone is (authentication) is half the job; the other half is what they may do (authorization). You'll get the signed-in user from a dependency, add roles and ownership rules that answer 401 or 403, and test every rule as each kind of user. Then you'll lock down a team's task board.

Updated: November 19, 2026

## [The Signed-In User](https://www.ask-codey.com/courses/python-web-apis/topics/fastapi-the-signed-in-user)

1. [Requiring a Signed-In User](https://www.ask-codey.com/lessons/fastapi-auth-current-user-dependency) (Journeyman): A get_current_user dependency reads the token from the Authorization header with OAuth2PasswordBearer, decodes it with PyJWT and loads the user from the database, so a route that asks for it serves only signed-in users and answers everyone else 401 with a WWW-Authenticate header.
2. [Roles and Ownership: 401 or 403](https://www.ask-codey.com/lessons/fastapi-auth-roles-and-ownership) (Journeyman): Signed in isn't the same as allowed, so a require_role dependency lets only the right role through, an ownership check compares a record's owner with the signed-in user's id, and both answer 403 Forbidden, while 401 stays for a request with no valid token.

## [Testing Who May Do What](https://www.ask-codey.com/courses/python-web-apis/topics/fastapi-testing-access)

1. [Testing Protected Routes](https://www.ask-codey.com/lessons/fastapi-auth-testing-protected-routes) (Journeyman): Tests for an API's rules about who may do what sign in inside a fixture and send the token in the Authorization header, try each rule as each kind of user and once with no token, and can override get_current_user with dependency_overrides as a shortcut, knowing it skips the token check.

## [Exercise: Team Task Board](https://www.ask-codey.com/courses/python-web-apis/topics/exercise-fastapi-team-task-board)

1. [Exercise: Team Task Board](https://www.ask-codey.com/lessons/exercise-fastapi-team-task-board) (Journeyman): Finish Crew Board's FastAPI task board with a get_current_user dependency, a require_role dependency and an ownership check, so anyone signed in reads the board and adds tasks, members change only their own tasks and only an admin deletes, and let the tests check every rule as each kind of user.

Source: https://www.ask-codey.com/courses/python-web-apis/chapters/fastapi-who-may-do-what
