This is the flow behind essentially every "Login with X" button on the web, and the one worth memorizing exactly.
client_id, a redirect_uri, the scope (what you're asking permission for — e.g. "read their email"), and a state parameter (covered in the CSRF section below).redirect_uri with a short-lived, single-use authorization code in the URL query string, plus the same state value you sent.client_secret — for an access token (and, for OpenID Connect, an ID token) by calling Google directly, server-to-server, at a token endpoint.Browser Your App (Client) Google (Auth Server)
| | |
|--- clicks "Login" ---------->| |
| |--- redirect to Google ------------>|
|<---------------------------- redirect w/ client_id, scope, state -|
|--- follows redirect, logs in & consents at Google ---------------->|
|<--- redirect back to redirect_uri with `code` + `state` ----------|
|--- browser forwards code -->| |
| |--- POST code + client_secret ----->| (server-to-server)
| |<--- access_token, id_token --------|
| |--- calls Google API w/ token ----->|
|<--- sets session cookie -----| |