How Sign in with Google works
You click Sign in with Google and you are in, without giving the site a password. See what the site and Google exchange in between and what the site really learns about you.
The tool could not be loaded. Check your connection and reload the page.
Use the arrow keys to move between steps. Click a term to see what it means, or any row of the timeline.
Terms in this step
Sent
Inside the message
Certificate checks
Where the time goes
Times are typical values for illustration, not measurements.
How it works
The site sends you to Google with the app's identifier, the redirect URI, the permissions it wants (scope) and a random state value. You type your password only at Google, the site never sees it.
Google checks that you are signed in and asks for consent the first time. Then it sends you back to the site with a one-time code valid for a few minutes. The redirect URI must match the registration exactly, otherwise Google refuses.
The site's server exchanges the code for tokens directly with Google, with its secret and the PKCE code_verifier. The ID token is a signed JWT telling the site who you are. It checks the signature, issuer, audience and expiry.
Finally the site creates its own session and sends a cookie. From then on it no longer needs Google. Times are typical values.
When it helps
- Understand what happens after you click Sign in with Google and what the site learns about you.
- Find the cause of a redirect_uri_mismatch error when setting up the sign-in.
- Explain to colleagues why to use PKCE even in a server-side app.
Glossary 18 terms
- Single sign-on (SSO)
- Signing in to many sites with one account (Google, Microsoft, Apple). No extra password to remember.
- OAuth 2.0
- The standard that gives an app limited access to your account elsewhere without knowing your password.
- Redirect URI
- Where Google sends you back after signing in. It must match the registered one exactly, otherwise the code could end up on someone else's site.
- State parameter
- A random value the site stores and sends along. After the return it compares them, so it never accepts a sign-in it did not start.
- PKCE
- Protection for the one-time code: the site sends a fingerprint of a secret value, and the value itself when exchanging the code. A stolen code is useless without it.
- OpenID Connect
- A layer on top of OAuth 2.0 for signing in. It adds the ID token that tells the site who you are.
- Scope
- The list of permissions an app asks for, for example only email and name. It never gets more than you allow.
- Session
- The server remembering that you are signed in. The browser proves it with a cookie holding a random session ID.
- Cookie
- A small piece of data a site stores in your browser, which sends it with every request. It typically keeps you logged in, so it is valuable.
- Authorisation code
- The one-time code Google sends you back to the site with. It is valid for a few minutes and the server exchanges it for tokens.
- Client secret
- The app's password at Google. Only the site's server knows it and sends it when exchanging the code for tokens.
- ID token
- A signed statement from Google of who you are: an identifier, email, name and expiry.
- Access token
- A short-lived key that lets the app call Google APIs within the scope you allowed.
- JWT
- JSON Web Token: JSON data encoded into one string and digitally signed. Anyone can read it, nobody can change it without breaking the signature.
- Digital signature
- Proof made with a private key that anyone can check with the public key. It can't be forged and reveals any change to the signed data.
- Subject identifier (sub)
- The permanent number of your Google account. The site recognises you by it even if you change your email.
- Consent screen
- The Google page that shows which data the app wants, where you agree or refuse.
- Code injection
- An attack where a stolen authorisation code is used in the attacker's own session to sign in as the victim. PKCE prevents it.
Frequently asked questions
// 01 Does the site get my Google password?
No. You type the password only on Google's page. The site gets a one-time code and, for it, tokens with the data you agreed to, typically your name, email and photo.
// 02 What does redirect_uri_mismatch mean?
The redirect URI in the request does not match the one registered in the Google Cloud console. A www, a trailing slash or http instead of https is enough.
// 03 Why PKCE when the server has a secret?
PKCE ties the code to the session that started the sign-in. If an attacker injects a stolen code into their own session, they lack the right code_verifier and Google refuses the exchange. It is recommended for all apps.
You may also need
Did this save you time?
The tools and simulations are free, ad-free and need no sign-up. If they helped you, you can send a contribution for coffee and new tools.
Donate via PayPalNeed a hand?
I build and maintain web applications in Laravel and PHP. If something on these pages is giving you trouble in a project, get in touch.
Get in touch