Identity and access
What is OAuth 2.0?
Definition
OAuth 2.0 is a delegated authorization framework: a user grants an application limited access to their data on another service without sharing a password.
Also known as: OAuth, OAuth2
OAuth 2.0 in more detail
The problem OAuth solved was password sharing. Before it, letting a calendar app read your contacts meant handing it your account password, with all the access that implies and no way to revoke it. OAuth replaces that with a redirect to the service you already trust, an explicit consent screen listing what is being requested, and a scoped, expiring token issued to the application — revocable at any time, and useless anywhere else.
Four parties appear in every flow: the resource owner (you), the client (the application asking), the authorization server (which authenticates you and issues tokens), and the resource server (which holds the data and accepts the tokens). The current recommendation for both web and mobile clients is the authorization code flow with PKCE, which binds the code to the client that requested it. The implicit flow and the password grant are discouraged and largely removed in OAuth 2.1.
The name says authorization, and that is worth taking literally: OAuth is about delegated access, not about proving identity. Using a raw access token as evidence of who the user is has produced real vulnerabilities, because a token issued for one application can be replayed at another. OpenID Connect is the thin layer built on top of OAuth that adds authentication properly, in the form of a signed ID token with an audience claim — which is what 'Sign in with Google' actually uses.
OAuth 2.0 example
Authorization code flow with PKCE
1. App creates a random verifier, sends its SHA-256 challenge:
GET https://auth.example.com/authorize
?response_type=code
&client_id=app123
&redirect_uri=https://app.example/callback
&scope=calendar.read
&state=xyz
&code_challenge=E9Me...&code_challenge_method=S256
2. User logs in at auth.example.com and approves the scope.
3. Browser is redirected back:
https://app.example/callback?code=SplxlO&state=xyz
4. App exchanges the code, proving it holds the verifier:
POST /token grant_type=authorization_code
&code=SplxlO&code_verifier=dBjftJ...
5. Response: { "access_token": "...", "expires_in": 3600,
"refresh_token": "...", "scope": "calendar.read" }OAuth 2.0 — common questions
- Is OAuth authentication or authorization?
- Authorization. It grants an application scoped access to resources. Authentication on top of OAuth is OpenID Connect, which adds an ID token asserting who the user is and which application that assertion was issued for.
- What is the difference between an access token and a refresh token?
- An access token is short-lived and sent with each API call. A refresh token is long-lived, kept private by the client, and exchanged at the authorization server for a new access token when the old one expires.
- What does PKCE protect against?
- An attacker intercepting the authorization code and redeeming it themselves. The client generates a secret verifier up front and must present it at the token exchange, so a stolen code alone is worthless. It is now recommended for all client types, not just mobile apps.
Keep reading
Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.
Browse the A-Z glossary