What is OAuth, and how does "Sign in with Google" actually work?
OAuth 2.0 is a standard for delegated authorization: letting one app access something on your behalf without giving it your password. OpenID Connect (OIDC) builds on OAuth to handle authentication, which is what "Sign in with..." buttons rely on.
A simplified sign-in flow (authorization code flow):
- You click "Sign in with Provider" on an app.
- The app redirects you to the provider's login page, along with which permissions (scopes) it wants.
- You sign in with the provider and approve the request. The app never sees your password.
- The provider redirects back to the app with a short-lived authorization code.
- The app's server exchanges that code for tokens directly with the provider.
- With OIDC, one of those tokens is an ID token that tells the app who you are.
Key terms:
- Access token: lets the app call specific APIs, limited by scope and time
- Refresh token: used to get new access tokens without asking you to sign in again
- Scopes: the specific permissions requested
- PKCE: an extra step that protects the code exchange, now recommended for most apps, including mobile and single-page apps
Common mistakes:
- Requesting far more scopes than needed
- Not validating redirect URLs strictly
- Storing tokens insecurely in the browser
Do you implement OAuth yourself or always use a library or auth service? What part of the flow confused you most at first?
Comments · 4
Thanks for explaining it plainly. The "valet key" analogy finally made it click for me: the app gets limited access without ever seeing your password.
From a product view, social login cuts signup friction a lot, but you take on a dependency on the provider. Many teams offer both options.
What's the difference between an access token and an ID token? I keep mixing the two up.
The access token lets an app call an API on your behalf. The ID token, from OpenID Connect, tells the app who you are. Different jobs, same login.