
Lesson 05 · 11 min
Auth and tests
The current user is a dependency too. And TestClient checks the API without a server.
OAuth2PasswordBearer extracts the token from the Authorization header. A get_current_user dependency verifies it and returns the user or raises 401. A route that needs sign-in just adds user: User = Depends(get_current_user).
Sign in to continue
The rest of this lesson opens after sign up
The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.