Token-Based Authentication Basics
Which of the following best describes how token-based authentication works in REST APIs?
- Each client receives a token after logging in and sends it with subsequent requests.
- The client and server share a persistent database connection.
- Cookies are automatically set and sent with every request by the browser.
- A session is created and maintained on the server for each client.
- All requests from any client are automatically trusted unless blacklisted.
Role of OAuth 2.0
In REST APIs, what is the primary purpose of using OAuth 2.0?
- To delegate user authentication and authorization to another service securely.
- To ensure data encryption during transmission.
- To store user passwords in a database.
- To prevent cross-site scripting attacks.
- To limit file upload sizes.
JWT Structure
What are the three main components of a JSON Web Token (JWT)?
- Header, Payload, Signature
- Username, Password, Timestamp
- Key, Value, Expiry
- Header, Footer, Hash
- Algorithm, Data, Secret
API Key Vulnerabilities
Which of the following is a common security risk when using API keys for authentication?
- Exposure of API keys in client-side code.
- API keys are encrypted and cannot be misused.
- API keys support complex access control lists.
- API keys automatically expire after each request.
- API keys only work with HTTPS.
Basic Authentication
How are credentials typically transmitted in Basic Authentication for REST APIs?
- As a Base64-encoded username and password in the Authorization header.
- Through a multipart/form-data payload.
- Stored in a server-side session object.
- Encrypted in a JWT token.
- Sent via HTTP cookies.
OpenID Connect Extension
OpenID Connect builds on top of which authentication protocol commonly used in REST APIs?
- OAuth 2.0
- SAML 2.0
- Kerberos
- HTTP Digest
- SOAP
Scopes in Authorization
What does the 'scope' parameter define in an authorization request?
- The permissions or access levels being requested.
- The network address of the server.
- The security algorithm used to encrypt data.
- The timeout value for the user session.
- The number of tokens a user can request.
Token Expiry Handling
Which is a recommended way to handle expired access tokens in REST APIs?
- Request a new token using a valid refresh token.
- Continue using the expired token until it is accepted.
- Switch to Basic Authentication automatically.
- Permanently disable the user's account.
- Increase the token lifetime in the client.
Authorization vs. Authentication
Which statement best distinguishes authorization from authentication in REST APIs?
- Authorization determines what actions a user is allowed to perform after they are authenticated.
- Authentication provides encryption for HTTP requests.
- Authorization verifies the user's identity.
- Authentication grants access to resources.
- Authorization is not relevant in REST APIs.
CORS and Tokens
Why is it important to configure CORS (Cross-Origin Resource Sharing) correctly when using token-based authentication in REST APIs?
- To control which domains can send authenticated requests to the API.
- Because CORS encrypts authentication tokens automatically.
- To prevent SQL injection in token payloads.
- Because CORS sets HTTP-only cookies for all requests.
- So that tokens can be exchanged for passwords.