They are not alternatives: OAuth 2.0 is an authorization framework (a protocol), while JWT is a token format. OAuth can use JWTs, but it does not have to. OAuth 2.0 - Defines how a client application obtains limited access to a resource on behalf of a user, without receiving the user's password. - Roles: resource owner (user), client (app), authorization server (issues tokens), resource server (API). - Grant types (flows): Authorization Code with PKCE (web, SPA and mobile apps), Client Credentials (service to service), Device Code (TVs and CLIs), plus refresh tokens. Implicit and password grants are deprecated. - Uses scopes to limit what the token allows (read:orders). - Example: "Sign in with Google" to let an app read your calendar. - OpenID Connect (OIDC) adds authentication on top of OAuth 2.0, introducing the ID token that says who the user is. JWT (JSON Web Token) - A compact, URL-safe format: header.payload.signature, Base64URL-encoded. - Contains claims (sub, exp, aud, iss, roles) and is signed (HS256 with a shared secret or RS256/ES256 with a private key), so receivers can verify it was not modified. - Self-contained: an API can validate it without calling the issuer. - Used as OIDC ID tokens (always JWTs), often as OAuth access tokens, and in custom login systems. How they relate in practice A typical setup: an OAuth 2.0 / OIDC provider (Microsoft Entra ID, Auth0, Keycloak) runs the Authorization Code flow and issues a JWT access token; the ASP.NET Core API validates that JWT with AddJwtBearer. Interview-ready summary: - OAuth = the process and rules for granting access. - JWT = one way to package the resulting token. - You can use JWT without OAuth (a custom login that issues JWTs), and OAuth without JWT (opaque tokens validated through token introspection).
Ravindra Wadile · · 0 likes