Explain the difference between Basic Auth, API Keys, and JWT/OAuth2, and when is each appropriate?

Last updated 29 June 2026

  • Basic Auth sends base64-encoded user:pass on every request with no scoping or expiry. It requires HTTPS and suits internal tools or prototypes.

  • API Keys are opaque tokens that identify the calling app, not a user. They are good for server-to-server access and rate limiting, but weak on fine-grained authorization and easy to leak.

  • OAuth2 is a delegation framework that issues scoped, expiring access tokens, often as JWTs (signed, self-contained claims). Use it for user login, mobile/SPA, or third-party access without sharing passwords.

  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication
All REST API interview questions