How "Sign in with ..." works

· 3 min read

#how-it-works#security

"Sign in with ..." lets an app learn who you are without ever seeing your password. The idea to keep: the app gets a short-lived code, not a password, and swaps it for tokens.

The short version

The app sends you to the provider's own sign-in page. The provider checks who you are, asks for your consent and sends you back to the app with a one-time authorization code. The app then trades that code for tokens in a direct request to the provider. OAuth 2.0 alone covers access, not identity. The "Sign in with" part is OpenID Connect on top: the app asks for the openid scope and gets an ID token, a JWT that says who signed in.

How an app signs you in through a provider Three columns: the app, the browser and the provider. Arrow 1 goes from the app to the browser, arrow 2 from the browser to the provider where you sign in, arrow 3 returns from the provider to the app with a code, arrow 4 sends the code to the provider, arrow 5 returns the tokens. App (client) Browser Provider 1 open provider page 2 sign in and agree 3 redirect back with a code 4 send the code 5 tokens come back Optional PKCE: code_challenge goes with 1, code_verifier with 4.
Simplified: the browser only carries the redirects in steps 1 to 3; steps 4 and 5 go straight between app and provider.

Step by step

  1. The app sends the browser to the provider with its client ID, scope (openid for sign-in), state and redirect URI.
  2. The provider signs you in and asks you to agree.
  3. It redirects the browser to the redirect URI with a one-time code and the same state.
  4. The app sends the code to the provider's token endpoint with its redirect URI.
  5. The provider returns an access token and, with OpenID Connect, an ID token.
Authorization code Access token
Reaches the app through the browser redirect a direct request to the provider
Lifetime 10 minutes at most (recommended) not published

Why it matters

Your password stays with the provider, which is the upside. The downside is that a sloppy setup can leak the code, so match the redirect URI exactly and use PKCE: RFC 9700 requires it for public clients such as mobile apps.

Sources