awesome-everything RU
↑ Back to the climb

Security

What OAuth is and why passwords are not the answer

Crux OAuth delegates access without sharing passwords. Three parties, two tokens, one trust model — explained through the dog-walker metaphor.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at junior altitude — the surface
◷ 7 min

A photo-printing app asks you to “connect your Google Drive.” You type your Google password directly into their form. Now that app can read every file, email, and photo in your account — forever. One breach of PrintPic and every Google-linked service is compromised. OAuth exists because this is the wrong way to share access.

The three parties

Every OAuth flow involves three parties working together:

  1. The client (your app, e.g. PrintPic). Wants limited access to a resource on behalf of the user. Never sees the user’s password.
  2. The authorization server (the identity provider, e.g. Google). Authenticates the user, issues tokens. The only party that holds the password.
  3. The resource server (the API, e.g. Google Drive). Accepts tokens to serve requests. Validates tokens against the authorization server.
OAuth three-party trust model
Client (App)
PrintPic — wants to upload photos. Never sees the password. Holds the access token.
Authorization Server
Google — holds the password. Issues access + ID tokens after user consents.
Resource Server
Google Drive — serves files. Validates access tokens. Knows nothing about the password.
The password lives only at the authorization server. Tokens flow to the other two.

The dog-walker metaphor

You hire a dog walker. You do not hand them your house key. Instead, you go to a key kiosk (the authorization server) and say “Frank can walk the dog Tuesdays 9–10am.” The kiosk prints Frank a single-use card that opens only the back gate, only on Tuesday, only for one hour. Frank loses the card — no problem, you revoke it at the kiosk. The card is the access token. The back gate is the resource API.

Two tokens, two jobs

A successful OAuth + OpenID Connect flow produces two distinct tokens:

  • Access token — authorizes API calls. The client sends it in the Authorization: Bearer header. It says “the holder may do X.” The resource server accepts it without needing to know the user’s identity.
  • ID token — proves who the user is (OpenID Connect layer). Always a JWT. Contains claims like sub (stable user ID), email, name. The client reads it to know who just signed in. Never sent to APIs.

The access token answers: “can this app do thing X?” The ID token answers: “who is the user?”

Quiz

Why is OAuth safer than giving an app your username and password?

Quiz

What is the difference between an access token and an OpenID Connect ID token?

Order the steps

Put the 'Sign in with Google' flow in order:

  1. 1 User clicks 'Sign in with Google' on the app
  2. 2 App redirects browser to Google's /authorize endpoint
  3. 3 User logs into Google and approves the requested scopes
  4. 4 Google redirects browser back to the app with a one-time code
  5. 5 App's server exchanges the code for an access token and ID token at Google's /token endpoint
  6. 6 App verifies the ID token signature and reads the user's identity claims
Recall before you leave
  1. 01
    Name the three parties in an OAuth flow and one sentence about each.
  2. 02
    What is the difference between an access token and an ID token?
  3. 03
    Why is token theft less catastrophic than password theft?
Recap

OAuth solves the credential-sharing problem: instead of handing your password to every app, you authorize the identity provider to issue a short-lived scoped token. The three parties — client, authorization server, resource server — divide trust so no party needs to trust all the others. OpenID Connect adds an identity layer on top via a signed ID token. A stolen token is scoped, short-lived, and revocable; a stolen password is not.

Connected lessons
appears again in202
Continue the climb ↑Authorization code flow with PKCE
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.