OAuth 2.0 is an authorization framework that enables third-party applications to obtain limited access to a user's resources without exposing their credentials. It is the foundation of modern API authorization used by Google, Facebook, GitHub, and virtually every major platform.
OAuth 2.0 defines four grant types for different scenarios: Authorization Code (for server-side apps), Implicit (deprecated, for SPAs), Client Credentials (for machine-to-machine), and Resource Owner Password Credentials (for trusted apps). The key players are the Resource Owner (user), Client (app), Authorization Server, and Resource Server.
In the Authorization Code flow, the client redirects the user to the authorization server's login page. After authentication, the user grants permission, and the server redirects back to the client with an authorization code. The client exchanges this code (along with its client secret) for an access token and optionally a refresh token. The access token is then sent with API requests to access protected resources.
JWT is a token format, while OAuth 2.0 is an authorization framework. OAuth 2.0 can use JWTs as access tokens, but they are independent concepts. OAuth handles authorization, JWT is a token format.
No, OAuth 2.0 is an authorization protocol. For authentication on top of OAuth 2.0, use OpenID Connect (OIDC), which adds an ID token and userinfo endpoint.
OAuth 2.0 is a modern, lightweight authorization framework ideal for APIs and mobile apps. SAML is an older XML-based protocol primarily used for enterprise SSO. OAuth is simpler and more flexible.