Comparison
OAuth vs JWT: What's the Difference (and Why It's the Wrong Question)
TL;DR
| OAuth 2.0 | JWT | |
|---|---|---|
| What it is | An authorization framework (protocol) | A token format (data structure) |
| Answers | How do I get access on a user's behalf? | How do I encode & verify claims? |
| Defines | Flows, roles, endpoints, scopes | Header.payload.signature encoding |
| Token format | Opaque or JWT (your choice) | Always a JWT |
| Used for | Third-party access, 'Login with…' | The token OAuth (or your app) issues |
| Relationship | Can issue JWTs as access tokens | Often the token inside an OAuth flow |
The options in depth
OAuth 2.0 (framework)
A protocol for delegated authorization — 'let app X act on my behalf'.
Good for
- ·Third-party / delegated access to APIs
- ·'Login with Google/GitHub' (with OIDC)
- ·Separating the authorization server from resource servers
Avoid when
- ·You just need to encode claims in a token (that's JWT)
- ·A simple first-party login where full OAuth is overkill
JWT (token format)
A signed, self-contained token — the data structure, not the protocol.
Good for
- ·Encoding verifiable claims in a compact token
- ·Stateless verification across services
- ·The access_token / id_token inside an OAuth/OIDC flow
Avoid when
- ·You actually need a delegation protocol (that's OAuth)
- ·You need easy revocation without extra machinery
Which one should you pick?
→ Do I need OAuth or JWT for my app?
If you're letting users grant a third-party app access to their data, or adding 'Login with Google', you need OAuth 2.0 (with OpenID Connect for login). If you just need to issue and verify a login token for your own API, a JWT from your own endpoint is enough — no full OAuth required.
→ Is a JWT an OAuth token?
It can be. OAuth issues access tokens, and those tokens may be JWTs (or opaque strings). So a JWT is often used as an OAuth access or identity token, but a JWT by itself isn't 'OAuth' — it's just the format.
Common pitfalls
- ⚠Treating them as competing choices: OAuth is a protocol, JWT is a format. The real decision is 'do I need delegated authorization (OAuth)?' and separately 'what token format do I use (JWT or opaque)?'
- ⚠Building your own OAuth flow from scratch: use a vetted library or identity provider. OAuth has many security-sensitive details (PKCE, state, redirect URI validation) that are easy to get wrong.
- ⚠Assuming an OAuth access token is always a JWT you can decode: some providers issue opaque tokens you must introspect, not decode.
Frequently Asked Questions
Is JWT the same as OAuth?
No. OAuth 2.0 is an authorization framework (a protocol for getting access on a user's behalf); JWT is a token format (a way to encode and sign claims). They're frequently used together — OAuth can issue a JWT as its access token — but they operate at different layers.
Can I use OAuth without JWT?
Yes. OAuth doesn't require JWTs; the access token can be an opaque string that the resource server validates by calling the authorization server's introspection endpoint. JWTs are popular because they allow stateless local verification, but they're optional.
Related comparisons
JWT vs Session
JWTs and server-side sessions are the two dominant ways to keep a user logged in. Sessions store state on the server and hand the browser an opaque cookie; JWTs are self-contained signed tokens the client carries. This guide compares statefulness, revocation, scalability, and security so you can pick the right one.
HS256 vs RS256 vs ES256
HS256 is symmetric (shared secret), RS256 and ES256 are asymmetric (public/private keypair). This guide explains when each JWT signing algorithm is the right choice.