PythonFan.org
Toggle Menu
Home
Online Python Compiler
Tutorials
Python FastAPI
Python Pandas
Python PyTorch
Python Seaborn
Blog
All Posts
FastAPI Authentication & Authorization
Assess your knowledge of OAuth2,JWTs,and security in APIs.
1. Which OAuth2 flow is commonly used for username/password authentication in FastAPI?
Authorization Code Flow
Password Flow
Client Credentials Flow
Implicit Flow
2. What dependency is used to retrieve the OAuth2 token from the request in FastAPI?
OAuth2PasswordBearer
TokenDependency
AuthJWT
BearerTokenExtractor
3. Which is the recommended approach for storing passwords in FastAPI applications?
Plaintext
MD5 Hashing
bcrypt Hashing
Base64 Encoding
4. What HTTP status code is returned by FastAPI when authentication credentials are missing?
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
5. Which Pydantic model is used to handle username/password input for OAuth2 login in FastAPI?
UserLogin
OAuth2PasswordRequestForm
TokenRequest
AuthForm
6. What is the primary purpose of OAuth2 scopes in FastAPI?
Encrypting tokens
Limiting access to specific resources/actions
Generating token signatures
Storing user passwords
7. Select all valid password hashing libraries compatible with FastAPI for secure password storage.
bcrypt
passlib
md5
cryptography
8. Which components are part of a JSON Web Token (JWT)?
Header
Payload
Signature
Encryption Key
9. Which of these can be used to implement authentication in FastAPI?
Bearer Tokens
API Keys
OAuth2
Session Cookies
10. What are common use cases for FastAPI dependencies in authentication/authorization?
Retrieving the current user from a token
Validating user roles (e.g., admin)
Checking OAuth2 scopes
Hashing passwords during user registration
11. FastAPI requires the use of JWT (JSON Web Tokens) for implementing authentication.
True
False
12. The OAuth2PasswordBearer dependency automatically validates the token's signature and expiration.
True
False
13. In FastAPI, you can raise an HTTPException with status code 403 to deny access to unauthorized users.
True
False
14. What does JWT stand for? (full name)
15. Name the FastAPI dependency that extracts the API key from the request headers (common class name).
Reset
Answered 0 of 0 — 0 correct