OAuth in Five Steps, Without the Big Words
Your app wants a user’s calendar, CRM or drive in another tool, and you must not ask for their password. With OAuth, the user approves on the real site, and your app gets a token for only what they approved. First, you register your app once with the provider and get a client ID and a client secret.
The five steps
- Your app sends the user to the provider’s login page, with the list of what it wants (scopes).
- The user logs in there, on the real site, and says yes.
- The provider sends the user back to your app with a short-lived code. It can be used only once.
- Your server swaps that code, plus your client secret, for an access token. The token never passes through the browser.
- Your app calls the API with the token, usually as "Authorization: Bearer <token>".
GET /authorize?response_type=code
&client_id=my-app-id
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
&scope=calendar.read
&state=k8Jq2x... HTTP/1.1
Host: auth.example.comStep 1 as an example request, the shape and not a real endpoint. The parameter names are the ones RFC 6749 defines; scope names are made up by each provider.
The two small things that keep it safe
- state: a random value tied to the user’s session. Refuse any callback where it does not match. This stops an attacker from linking their account to your user (RFC 6749 section 10.12).
- PKCE (said "pixy"): a one-time secret for each login, so a stolen code is useless. Apps that cannot keep a secret must use it, and current advice (RFC 9700) recommends it for server apps too.
Scopes are the part people skip. Ask only for what you need, because the user usually sees that list before saying yes.
Do this in 60 secondsNext time you click "Sign in with..." on a site, look at the address bar on the provider’s page. Find client_id, redirect_uri, scope and state. That is step 1.
Today’s AI angleAn AI agent should never ask for a password in chat. The user approves on the provider’s page, and the token stays in the tool layer. Ask for the fewest scopes the agent needs.