Overview

Chapter 1. What is OAuth 2.0 and why should you care?

OAuth 2.0 is a widely adopted security framework that lets users delegate limited access to their data without sharing passwords, enabling applications to call web APIs securely across websites, mobile, and native apps. It replaces fragile approaches like credential replay and universal developer keys with purpose-built tokens that act like a “valet key,” granting only the specific rights needed for a task. Designed for today’s API-driven ecosystem, OAuth balances security and usability, making cross-service integration practical for everything from consumer apps to enterprise systems.

At its core, OAuth 2.0 involves four main roles: the resource owner (user), the client (app), the protected resource (API), and the authorization server. The client sends the user to the authorization server to authenticate and approve requested scopes; in return, the client obtains an access token that the API can validate and enforce according to the user’s delegated permissions. This design keeps user credentials away from clients, limits access by scope and time, supports revocation, and scales beyond browser sessions and HTTP Basic Auth to fit non-interactive API calls—while still enabling user choice through consent and patterns like Trust On First Use when appropriate.

OAuth 2.0 delivers strong delegation but has boundaries and trade-offs. It is not an authentication protocol by itself, does not define token formats, cryptographic methods, or user-to-user delegation, and is intended to run over HTTPS. Its flexibility and modularity power many use cases but can create incompatibilities or insecure implementations if options are misapplied. Complexity is intentionally shifted from clients to authorization and resource servers, concentrating risk where it’s easier to harden. Used correctly, OAuth 2.0 provides a focused, extensible foundation that other technologies can build upon to form complete, secure systems.

An OAuth authorization dialog from the exercise framework for this book
Connecting the client on behalf of the resource owner
Copy the resource owner’s credentials without asking
Ask for the resource owner’s credentials, and replay them
Use a universal developer key, and identify the user on whose behalf you’re (allegedly) acting
A service-specific password that limits access
The OAuth authorization server automates the service-specific password process
The OAuth process, at a high level
Different levels of trust, working in parallel
Notional relative numbers of components in an OAuth ecosystem

FAQ

What is OAuth 2.0 in simple terms?OAuth 2.0 is a delegation protocol that lets a resource owner allow a third‑party application to access a protected HTTP service on their behalf using tokens, without sharing passwords. Think of the token like a “valet key” that grants limited, revocable access instead of full control.
Why do we need OAuth instead of sharing passwords?Sharing passwords forces clients to impersonate users, store replayable credentials, and creates high risk if a client is compromised. It also fails across different security domains and breaks with modern login methods. OAuth replaces this with scoped, time‑limited, revocable tokens that represent delegated access, not the user’s primary credential.
Who are the main actors in OAuth?- Resource owner: typically the end user who can delegate access to their data or actions.
- Client: software that wants to call the protected API on the user’s behalf.
- Protected resource: the API or service holding the data/actions.
- Authorization server: issues access tokens to clients after the resource owner authorizes them.
How does OAuth work at a high level?The client sends the user to the authorization server, where the user authenticates and approves specific permissions (scopes). The client then exchanges the approval for an access token. The client uses the token to call the protected resource. The user’s credentials never pass through the client.
What are “scopes” and why do they matter?Scopes express the specific permissions the client is requesting (for example, read selected photos but not delete). They constrain what the access token can do and help users and APIs enforce least‑privilege access. They also make revocation and auditing more meaningful.
What did developers do before OAuth, and what went wrong?Common patterns included replaying user credentials on other services, asking users for passwords to remote systems, using powerful developer keys, or issuing service‑specific passwords. These approaches enable impersonation, require risky credential storage, cause catastrophic blast radius on breach, and are hard for users to manage or revoke precisely.
What isn’t OAuth 2.0?It isn’t an authentication protocol by itself; it doesn’t define authorization processing logic; it doesn’t define a token format; it doesn’t define cryptographic methods; it isn’t a single monolithic flow; and it isn’t meant to run outside HTTPS without a suitable secure mapping.
How does OAuth enable user-driven security decisions?Users explicitly approve a client’s requested scopes at runtime, often following a Trust On First Use (TOFU) model. Systems can combine whitelists, blacklists, and a “graylist” where users decide on first encounter. This frames choices in terms of functionality (“allow this app to do X?”) instead of low-level security settings.
What are the trade-offs and pitfalls of OAuth 2.0?Complexity shifts to authorization servers and resource servers, which must be robust and secure. Optional features and flexibility can cause incompatibilities or insecure deployments if misapplied. Using TLS, validating redirects, handling tokens safely, and following the threat model are essential.
Where does OAuth 2.0 fit best?It’s designed for HTTP APIs and works well for web, native, and mobile clients, from small apps to large-scale services. It relies on HTTPS, and while extensions exist for other protocols (for example via SASL or CoAP mappings), OAuth’s sweet spot is securing modern API-centric interactions.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • OAuth 2 in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • OAuth 2 in Action ebook for free