OAuth 2.0
Delegated access with OAuth 2.0, from the problem it solves through the authorization code flow, tokens, client types and production operations.
Start with The problem OAuth solves
Foundations
The problem OAuth solves, the roles in every OAuth exchange, and the vocabulary the rest of the OAuth lessons build on.
- The problem OAuth solvesReturn to the photo-printing example to see why sharing a password fails, how access tokens help, and where OAuth and OpenID Connect differ.
- Roles and endpointsSee which decisions belong to each of the four OAuth roles, and follow the responsibilities of the authorization endpoint, client redirect URI, token endpoint, and photo API.
- Trust boundariesExplore what clients, authorization servers, and resource servers must check before trusting OAuth messages and allowing access.
- Grants, scopes, and consentDistinguish OAuth grants, scopes, and consent, and learn how requested access relates to what a service actually permits.
- Public and confidential clientsLearn how a client deployment affects credential protection, why client IDs are not secrets, and how PKCE protects an authorization code exchange.
Other grants and flows
Device, client credentials, refresh and assertion grants, and how to choose the right flow for an application.
- The refresh token grantUnderstand how refresh tokens extend an existing authorization, how rotation replaces them, and what a client does when refresh fails.
- Client credentialsLearn how a confidential client obtains an access token as itself, with no user involved, and why that access should stay narrow.
- Device authorizationFollow the device authorization grant for a photo frame, from user codes and polling to phishing risks with codes someone else started.
- JWT and SAML assertion grantsSee how a client exchanges a signed JWT or SAML assertion for an access token, and what the authorization server must check first.
- Choosing a flowChoose between OAuth grants by asking whose access it is, how a person can authorize it, and whether access must continue.
Clients and registration
Client IDs and registration, redirect URIs, client authentication, and keeping client credentials current.
- Client IDs and registrationLearn what a client registration records, why a client ID is an identifier rather than a credential, and when one application needs several clients.
- Redirect URIs and client metadataRegister return addresses for web, mobile, and desktop clients, and see why client names and logos are claims while technical settings limit requests.
- Client authentication methodsCompare the ways a confidential client proves itself at the token endpoint, from client secrets to signed JWTs and certificates, and handle invalid_client.
- Secrets and signed assertionsFollow a client secret and a private_key_jwt client assertion through a token request, and see what the server checks and why the private key never travels.
- Rotating client credentialsReplace client secrets and keys without downtime by overlapping old and new credentials, and respond when a client credential has leaked.
Tokens and resource servers
What access and refresh tokens contain, how APIs validate them, scopes and audiences, introspection and revocation.
- Using access tokensSend an access token the way APIs expect, treat it as opaque, replace it before it expires, read WWW-Authenticate errors, and keep it away from other hosts.
- Token formats and validationCompare reference tokens with self-contained JWT access tokens, read the JWT access token profile, and follow the photo API through its validation checks and a key rotation.
- Scopes and audiencesSee why a token names both what it allows and which API may accept it, how the audience is chosen, and how to design scopes that stay useful.
- Enforcing access at an APIFollow an API from a validated token to a decision: map routes to scopes, check each object against the user, and choose between 401, 403, and 404.
- Refresh tokens and rotationSee what an authorization server stores for refresh tokens, how idle and absolute lifetimes work together, how to rotate atomically, and which events should end a token family.
- Token introspectionFollow an API as it asks the authorization server about a token, reads active and inactive answers, caches them safely, and fails closed when no answer comes.
- Token revocationRevoke a refresh token when a person disconnects, see what revocation can and cannot reach, and compare a client revoking its tokens with a person removing the connection.
Application architectures
How browser, native, backend and service-to-service applications use OAuth safely.
- Server-rendered web applicationsSee why a website backend makes a strong OAuth client: tokens stay encrypted on the server, sessions and connections end separately, and background jobs refresh safely.
- Browser applicationsRun the authorization code flow in JavaScript as a public client, and see what cross-origin requests, token storage, refresh rules, and injected script mean for it.
- Backends for frontendsMove a browser application's tokens to a small backend, compare three designs, and protect the backend's cookie-based endpoints against cross-site request forgery.
- Native applicationsLearn why mobile and desktop apps sign in through the system browser, redeem codes as public clients with PKCE, and keep refresh tokens in platform secure storage.
- Command-line toolsCompare ways a command-line tool can obtain access, from a loopback redirect to personal access tokens, and keep its tokens out of logs, arguments, and history.
- Service-to-service accessDecide how one API calls another on a user's behalf, why forwarding tokens and trusting headers fail, and how services prove their own identity without long-lived secrets.
Security and failure cases
The ways OAuth deployments fail, such as redirect URI mistakes, code interception and token theft, and the defenses for each.
- Redirect URI validationFollow an attacker who bends a redirect URI to collect authorization codes, see how careless matching fails, and learn what the server and client each check.
- Request correlation and CSRFSee how a forged callback can link your account to an attacker's photos, which session-bound checks stop it, and how SameSite cookies affect the return trip.
- Code interception and injectionFollow a stolen authorization code through interception and injection, see why client authentication cannot stop injection while PKCE can, and handle a reused code.
- Authorization server mix-upWalk through a mix-up attack in which a compromised authorization server tricks a client into handing over another server's code, and compare the defenses.
- Token theft and replayTrace where access tokens leak, what a replayed bearer token allows and for how long, and how lifetimes, audiences, and sender-constrained tokens limit the damage.
- Refresh token theftSee why refresh tokens attract thieves, how client authentication and rotation block or reveal their use, where rotation leaves a gap, and how to contain a theft.
- OAuth security best practicesReview the OAuth 2.0 Security Best Current Practice role by role, learn the few protections not covered elsewhere, and see how OAuth 2.1 consolidates them.
Implementation and operations
Building, testing, monitoring and troubleshooting OAuth in production.
- Implementing a clientStructure an OAuth client around a maintained library, configure it from metadata, give each job one home in the code, and keep environments and secrets apart.
- Authorization server responsibilitiesSee what running an authorization server involves, from reviewing clients and recording approvals to protecting signing keys, auditing, limiting abuse, and ending grants.
- Resource server responsibilitiesKeep an API that accepts tokens correct over time: trusted issuers per environment, key rollover, clocks, caches, scope changes, rejection monitoring, and outages.
- Tracing and troubleshooting exchangesFollow one connection attempt across browser redirects and back-channel calls, recognize common OAuth failures, and investigate them without leaking codes or tokens.
- Testing an OAuth integrationTest token validation with crafted tokens, client checks with deliberately wrong callbacks, refresh concurrency with a fake server, and the whole flow with test clients.
- Operating and monitoring an integrationDecide which OAuth failures to retry, choose the signals worth monitoring, behave sensibly during an authorization server outage, and prepare for incidents and log retention.
History, legacy, and migration
Where OAuth came from, what changed from OAuth 1.0 to OAuth 2.1, and how to migrate older integrations.
- From OAuth 1.0 to OAuth 2.0Trace OAuth from its 2007 community specification and signed requests, through the 2009 session fixation fix, to OAuth 2.0, bearer tokens, and separate authorization servers.
- The implicit grantSee how the implicit grant returned access tokens in the URL fragment, why browser applications once needed it, what went wrong, and what current guidance says.
- The password grantUnderstand how the password grant exchanged a username and password for tokens, why OAuth 2.0 included it, and why current security guidance forbids it.
- Migrating older integrationsMove an authorization server and its clients away from legacy patterns by taking inventory, choosing replacements, tightening settings, and enforcing each change gradually.
- How the specifications evolveLearn how OAuth documents move from Internet-Draft to RFC, where registries and the OpenID Foundation fit, what OAuth 2.1 consolidates, and how to read MUST and SHOULD.