OAuth2 Password Flow — Login That Issues Tokens — Concept Check
Questions on OAuth2 Password Flow — Login That Issues Tokens. OAuth2PasswordRequestForm receives username/password at /token, the app returns a bearer token, and OAuth2PasswordBearer extracts it on every protected call — the login skeleton behind the Swagger Authorize button.
Questions in this quiz
8 questions on OAuth2 Password Flow — Login That Issues Tokens — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer is testing an API using Swagger UI. They notice a padlock icon next to some endpoints. What does this icon indicate?
- AThe endpoint requires authentication via OAuth2Bearer tokens.
- BThe endpoint is protected by server-side sessions.
- CThe endpoint is publicly accessible without authentication.
- DThe endpoint uses cookie-based authentication.
2.A user attempts to log in via the /token endpoint with incorrect credentials. What response should they expect?
- AA 404 Not Found status indicating the endpoint is missing.
- BA 403 Forbidden status with a detailed error message.
- CA 401 Unauthorized status with a WWW-Authenticate header.
- DA 200 OK status with an error message in the body.
3.An API is designed to handle requests from both mobile apps and web browsers. Why might it use bearer tokens instead of sessions?
- ABearer tokens require less server-side storage than sessions.
- BBearer tokens are more secure than sessions.
- CBearer tokens allow stateless verification, supporting horizontal scaling.
- DBearer tokens are easier to implement than sessions.
4.A developer mistakenly believes that OAuth2PasswordBearer automatically validates the token's contents. What is the correct behavior?
- AOAuth2PasswordBearer validates the token's contents by default.
- BOAuth2PasswordBearer only extracts the token; validation is separate.
- COAuth2PasswordBearer checks the token's expiration date automatically.
- DOAuth2PasswordBearer verifies the token's signature.
5.A team is using FastAPI to build an API. They notice the 'Authorize' button in their Swagger UI. What is its purpose?
- AIt lists all API endpoints available.
- BIt provides detailed API documentation.
- CIt generates client-side code for API interaction.
- DIt allows users to log in and test protected endpoints.
6.A developer claims that using bearer tokens eliminates the need for CSRF protection. Why might this be true?
- ABearer tokens are not stored in cookies, avoiding classic CSRF.
- BBearer tokens are encrypted, preventing CSRF attacks.
- CBearer tokens are single-use, making CSRF irrelevant.
- DBearer tokens require server-side validation, which stops CSRF.
7.What happens if a request to a protected endpoint is made without an Authorization header?
- AThe server redirects the client to the login page.
- BThe server responds with a 401 status and a WWW-Authenticate header.
- CThe server processes the request without authentication.
- DThe server responds with a 403 Forbidden status.
8.A developer is confused about why the API returns 'incorrect username or password' instead of specifying which one is wrong. What is the reason for this?
- ATo avoid revealing sensitive information.
- BTo comply with OAuth2 specifications.
- CTo prevent user enumeration by attackers.
- DTo simplify error handling in the code.