The Auth Playbook preview

Chapter 1: Why auth matters more than you think

In 2023, CircleCI disclosed a security incident: an attacker compromised an engineer’s laptop, stole a session token, and accessed customer environment variables including API keys and secrets. The breach vector was not a zero-day. It was a session token that lasted too long, on a system that did not require re-authentication for sensitive operations. CircleCI rotated every key, every token, every secret for every customer. The remediation cost was measured in weeks of engineering time and an unquantifiable amount of trust.

Every platform you build will face a moment like this. A moment where the question is not whether your auth system works on the happy path, but whether it holds under the unhappy one: the stolen token, the enterprise customer who demands SAML by Friday, the pricing surprise when your free-tier auth provider’s bill arrives, the migration you never planned for when your team outgrows the tool you picked on day one.

Auth is not a feature. It is the foundation every other feature sits on. Get it right and users never think about it. Get it wrong and they leave, or worse, they stay and get compromised.

After this chapter you will be able to

  • Articulate what a production auth system actually guards against
  • Identify the full scope of a platform auth system (not just the login form)
  • Recognize the real costs of auth failures: reputational, financial, and engineering
  • Map your current auth posture against what this handbook covers

Why this matters

You might not think you need to know auth deeply. You might have added a login form to your app with a library or a provider, and it works. Users can sign up, they can sign in, and nobody has complained. The code shipped. The tickets closed.

Here is the problem: that login form is the easy part. Auth is everything that happens after clicking “Sign In” - and everything that happens when it breaks. It is the session token that gets leaked from a client-side bug. It is the enterprise prospect who asks about SAML SSO and RBAC during the security review and you have no answer. It is the Auth0 bill that hits $700 per month when you cross a MAU tier you did not know existed. It is the realization, six months in, that you built permissions as a role column on the users table and now your biggest customer needs per-project editors with fine-grained access.

A platform with 10 paying customers has the same auth surface area as one with 10,000. The consequences just scale differently. The small platform loses a customer and a hard-to-rebuild reputation when passwords leak. The large platform makes the front page of a security news site.

Auth is also the single area where LLM coding tools are most dangerous. An LLM will happily generate password hashing code that uses MD5, JWT validation that skips signature verification, or an OAuth flow that omits PKCE. It will produce code that looks correct and compiles and ships to production, and it will have a vulnerability that an attacker finds before you do. Chapter 12 covers the security hardening you need precisely because AI tools are bad at auth.

What a production auth system actually handles

A login form is one endpoint - usually POST /login with an email and a password. A production auth system is everything in this list:

Credential management. How do you store passwords so that a database breach does not expose every user’s plaintext password? (Argon2id hashing, Chapter 3.) How do users reset passwords without opening an account takeover vector? (Secure reset tokens, rate-limited endpoints, Chapter 3.) What happens when a user’s password appears in a public breach database? (Breached password detection, Chapter 3.)

Session integrity. Once a user authenticates, how do you know they are the same person on every subsequent request? (Session tokens, cookie security flags, token rotation, Chapter 4.) How do you handle “remember me” without creating a long-lived token that, if stolen, grants permanent access? (Persistent tokens with rotation, Chapter 4.)

Federation. Your SaaS customers do not want another password to manage. They want to authenticate with their existing identity provider - Okta, Azure AD, Google Workspace. Supporting this means implementing SAML 2.0 or OpenID Connect, correctly, with certificate management, metadata exchange, and logout propagation. (Chapters 5, 8, and 9.)

Authorization. Authentication says who someone is. Authorization says what they can do. A platform with 10 users on a shared admin role does not need RBAC. A platform with 100 users across 20 organizations, where some people can edit documents but not delete them and others can manage billing but not view source code, absolutely needs a proper authorization model. (Chapter 10.)

API authentication. Your platform has an API. Maybe it is consumed by a mobile app, maybe by customer integrations, maybe by your own frontend. Machines need to authenticate too: API keys, OAuth client credentials, service accounts, webhook signatures. (Chapter 11.)

Security hardening. Rate limiting on login endpoints so attackers cannot brute-force passwords. CSRF protection so a malicious site cannot make requests on behalf of a logged-in user. Security headers that prevent token leakage. Session anomaly detection. Credential stuffing defenses. (Chapter 12.)

Provider selection and migration. The auth provider you choose on day one will not be the one you have on day 1000. You will outgrow it, or it will out-price you, or you will need features it does not support. Planning for migration before you need it is the difference between a two-week project and a two-month crisis. (Chapters 6, 7, and 13.)

A login form handles one of these. A production auth system handles all of them. This handbook covers the full set.

The cost of getting it wrong

Auth failures are not abstract. They have concrete costs that compound:

The immediate cost: engineering hours to diagnose, patch, and roll credentials. For a significant breach, this often consumes the entire engineering team for days or weeks. Every feature in progress stops. Every roadmap item slides. The opportunity cost alone can exceed the direct cost of the incident.

The customer cost: users who leave and never come back. A Stack Overflow survey of 49,000 developers in 2025 found that security and privacy concerns are the number one reason developers abandon tools. You can have the best product in your category. If users do not trust your auth, they will not use your product.

The enterprise cost: deals that die in security review. Enterprise customers send questionnaires. One question is always about authentication: “Do you support SAML 2.0 SSO with our identity provider?” If the answer is no, the deal is often dead - not deferred, not negotiated, just gone. The same applies to SCIM provisioning, audit logging, and RBAC. These are not nice-to-have features for enterprise sales. They are table stakes.

The accumulated engineering debt: every auth shortcut compounds. The hardcoded role column. The session token with no expiration. The password hash that uses bcrypt with a cost factor of 4 because it was faster during development. Each shortcut is a small, rational decision in the moment. Together they are a system that needs to be rebuilt from scratch when the first real customer arrives.

What this handbook covers

This handbook walks through authentication and authorization from first principles to production migration, in the order you would encounter them as a platform grows:

Ch 1-2    The stakes and the mental model
Ch 3-4    Local auth: passwords, sessions
Ch 5       OAuth 2.0 and OIDC: the protocol layer
Ch 6-7    Provider landscape: SaaS and self-hosted options
Ch 8-9    Enterprise federation: SAML, OIDC implementation
Ch 10      RBAC: design and enforcement
Ch 11      Auth for APIs
Ch 12      Security hardening and threat modeling
Ch 13      Migration: moving between providers
App A     Provider pricing reference

Chapters 3 through 13 build on each other but can be read independently if you are solving a specific problem. If you need to evaluate providers, read Chapter 6. If you need to implement SAML for an enterprise customer, read Chapter 8. If you are planning a migration, read Chapter 13.

Code examples appear in three languages: Go, Node.js (Express), and Python (FastAPI). These were chosen because they represent the most common backend stacks for the audience. Each example is complete, runnable, and minimal - enough code to demonstrate the pattern, not enough to distract from it. When a concept is language-agnostic (mental models, protocol flows, provider comparison), the prose carries the explanation without tying to a specific stack.

What this handbook does not cover

Honesty about scope is necessary in a topic this broad. Here is what is deliberately excluded:

  • Programming language fundamentals. The handbook assumes you can read Go, Node.js, or Python code. It does not teach syntax, package management, or tooling from scratch.
  • Hardware Security Modules (HSMs) and FIPS 140-2 certification. Cryptographic key management at the hardware level is an operations specialty beyond the scope of a platform builder’s guide.
  • Biometric template storage and matching. Face recognition, fingerprint matching, and the underlying biometric algorithms are not covered.
  • National digital identity schemes. Government-issued digital identity standards like eIDAS, Aadhaar, and GOV.UK Verify are not covered.
  • Physical access control and network perimeter auth. VPN authentication, Zero Trust Network Access, and building access control are separate domains.
  • WebAuthn/FIDO2 deep implementation. Passkeys are covered at the architectural level (Chapter 3) and in the provider comparison (Chapter 6), with guidance on when to adopt them. A full FIDO certification study guide belongs in a separate handbook.

If you need any of these, this handbook gives you the foundation to evaluate them intelligently. It does not replace specialist resources.

How this handbook handles AI assistance

AI coding tools generate auth code constantly. They generate it wrong constantly. An LLM has no memory of the NIST password guidelines, no awareness that the OAuth 2.1 draft removed the implicit grant, and no hesitation about writing jwt.decode() without signature verification. It will produce auth code that compiles and runs and is wrong in a way you may not catch until after a breach.

Throughout this handbook, code examples are annotated where AI tools commonly get them wrong. The rule is simple: read every line of auth code your AI generates. If you cannot explain why a particular pattern is correct, do not ship it. Auth is the one domain where “it works on my machine” and “the tests pass” are insufficient. You need to know that it is correct against the protocol, against the security best practice, and against the failure modes you have not yet encountered. This handbook gives you that knowledge.

Think of a production auth system as layered defenses, each stopping what the outer layer missed:

  • The drawbridge (login form). The first and most visible checkpoint. Validates credentials. If compromised, an attacker has a foothold. But a foothold is not access to everything.
  • The portcullis (session validation). Every subsequent request is challenged. A stolen credential is useless if the session itself is checked, rotated, and bound to the client. Session management is the layer most platforms skip after the login form ships.
  • The guard towers (RBAC). Authentication proves who you are. Authorization limits what you can reach. Even a valid session should not access every resource. Roles and permissions bound the blast radius of a compromise.
  • The inner keep (credential storage). Passwords, tokens, and secrets are not stored as plaintext. Hashing, encryption, and key management mean a database breach does not expose credentials that work elsewhere.

Each layer is useless if the one inside it fails. A strong password hash does not help if sessions are not validated. A strict RBAC model does not help if the attacker can request any resource with a stolen JWT. The rest of this handbook walks through each layer in the order you need them.

Key takeaways

  • Auth is not a feature. It is the foundation every other feature depends on. Shortcuts compound into rebuilding projects.
  • A login form is 10% of a production auth system. The other 90% is sessions, federation, authorization, API auth, security hardening, and migration planning.
  • Auth failures cost real money: engineering weeks lost to remediation, customers lost to distrust, enterprise deals lost to security reviews.
  • LLMs are particularly bad at writing correct auth code. The examples in this handbook annotate where AI tools commonly generate vulnerabilities.
  • This handbook covers the full spectrum, from password hashing through SAML federation to migration. You can read it front to back or jump to the chapter that addresses your current problem.

Further reading

Common pitfalls

  • Treating auth as a box to check before launch. Auth is the thing that will break first under load, under attack, or under a changed business requirement. Build it as if you will still be running it in two years, because you probably will.
  • Trusting AI-generated auth code without review. An LLM will write bcrypt.hash(password) and miss the salt rounds, cost factor, and pepper. It will write JWT validation that decodes but does not verify. Read every line.
  • Picking an auth provider solely on the free tier. The free tier is not a business model. Evaluate pricing at your projected scale, not your current one. Chapter 6 gives you the framework.

Checkpoint exercise

Write down your current auth posture in one paragraph. Include:

  1. How users sign up and sign in today (custom implementation or provider - which one?)
  2. How you store and validate sessions
  3. What would break if you had to add SAML SSO for one enterprise customer next month
  4. Whether you have ever tested what happens when a user’s session token is stolen and replayed

Do not share this anywhere. It is for you. Revisit it after reading Chapter 13 and compare what you would change.