What Happens When You Type a URL and Press Enter
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →"Sign in with Google" looks like one button but involves redirects, codes, tokens and a few important security checks. How OAuth 2.0 and OpenID Connect work, and how to implement them safely.
"Sign in with Google," "Continue with GitHub," "Log in with Apple." Users love social login because there's no new password to remember. Developers love it because there's no password to store. But the protocol underneath, OAuth 2.0, has a reputation for being confusing. Let's untangle it.
These two get mixed up constantly:
"Sign in with X" is OIDC (or a provider's OAuth flow used for login). Accessing a user's files or calendar via API is OAuth.
This is the recommended flow for web apps, mobile apps and single-page apps:
client_id (identifies your app)redirect_uri (where to send them back)scope (what you're asking for, like openid email profile)state (a random value to prevent CSRF)code_challenge (for PKCE, explained below)redirect_uri with a short-lived authorization code and the same state.code_verifier.PKCE (Proof Key for Code Exchange, pronounced "pixie") protects against someone intercepting the authorization code. Your app creates a random secret (code_verifier), sends a hashed version (code_challenge) at the start and the original at the exchange. An attacker with only the code can't complete the exchange. It's now recommended for all clients, not just mobile apps.
state. Compare the returned state with the one you stored. If it doesn't match, reject the login. This prevents login CSRF.A user might sign up with email and password, then later click "Sign in with Google" using the same email. Should those be the same account?
user_id, provider, provider_user_id), so one user can have several login methods.Use the provider's stable user ID, not the email, as the identifier. Emails can change.
You rarely need to implement OAuth from scratch, and you shouldn't. Mature options exist for every stack: framework auth libraries (for Next.js, Laravel, Django, Rails and others), or hosted authentication services that handle providers, sessions, MFA and account linking. They get the subtle details right.
What you still own: deciding what happens after login, protecting your own routes and checking permissions. (Security checklist.)
OAuth 2.0 handles authorization (granting access to resources). OpenID Connect builds on it to handle authentication, adding an ID token that tells your app who the user is.
A security extension where the client sends a hashed secret at the start of the flow and the original secret when exchanging the code, so an intercepted authorization code is useless on its own.
Yes, when implemented correctly with the authorization code flow, PKCE, state validation, exact redirect URIs and ID token validation. Using a well-maintained library makes this much easier.
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →There are dozens of HTTP status codes, but about fifteen cover nearly everything. What each one means, when to return it, and the mix-ups (401 vs 403, 301 vs 302) that confuse everyone.
Read →A, AAAA, CNAME, MX, TXT and NS records in plain English, why DNS changes seem slow, and the troubleshooting commands that tell you what is really going on.
Read →