0
0
HLDsystem_design~20 mins

API authentication (OAuth, JWT, API keys) in HLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Authentication Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding OAuth 2.0 Flow

Which step in the OAuth 2.0 Authorization Code flow is responsible for exchanging the authorization code for an access token?

AThe client redirects the user to the authorization server's login page.
BThe resource owner grants permission to the client application.
CThe client sends the authorization code to the authorization server's token endpoint.
DThe client uses the access token to access protected resources.
Attempts:
2 left
💡 Hint

Think about which step involves the client securely obtaining the token after user approval.

Architecture
intermediate
2:00remaining
Choosing API Key Storage Location

Where is the most secure place to store API keys in a client-server architecture to prevent unauthorized access?

AStore API keys in environment variables on the server side.
BStore API keys in the client-side JavaScript code for easy access.
CEmbed API keys directly in HTML meta tags.
DStore API keys in local storage of the user's browser.
Attempts:
2 left
💡 Hint

Consider where secrets should be kept hidden from users.

scaling
advanced
2:00remaining
Scaling JWT Validation in a Distributed System

In a distributed system with multiple API servers validating JWT tokens, what is the best approach to ensure consistent and scalable token validation?

AAPI servers store the JWT secret key and generate tokens themselves.
BEach API server fetches the public key from the authorization server on every request.
CAPI servers validate tokens by querying the authorization server synchronously for each request.
DAPI servers cache the public key locally and refresh it periodically.
Attempts:
2 left
💡 Hint

Think about reducing latency and load on the authorization server.

tradeoff
advanced
2:00remaining
Tradeoffs Between OAuth and API Keys

Which statement best describes a key tradeoff when choosing between OAuth 2.0 and API keys for API authentication?

AOAuth provides fine-grained access control but is more complex to implement than API keys.
BOAuth tokens never expire, making them simpler to manage than API keys.
CAPI keys support delegated access and user consent flows better than OAuth.
DAPI keys are more secure than OAuth because they do not require token exchange.
Attempts:
2 left
💡 Hint

Consider complexity and control features of each method.

estimation
expert
3:00remaining
Estimating Token Storage Requirements for JWTs

You expect 1 million active users, each making 10 API requests per minute. Each JWT token is 1 KB in size and stored in a cache for 15 minutes. Approximately how much memory (in GB) is needed to store all active tokens in the cache at peak usage?

AApproximately 10 GB
BApproximately 150 GB
CApproximately 250 GB
DApproximately 100 GB
Attempts:
2 left
💡 Hint

Calculate how many unique tokens are active in the cache at once and multiply by token size.