Tuesday, December 1, 2026

Building your own OIDC provider: what the server side actually teaches you

Nobody needs to build their own identity provider. Keycloak, Auth0, Entra ID — the mature options are right there. I built one anyway, and it's the most instructive side project I've run in years. This post is the map of what I built and why; the rest of the series goes deep on each piece.

The itch

I've integrated with OIDC providers plenty of times — configured redirect URIs, validated JWTs, cursed at claim mappings. But integrating with a black box teaches you the client half of the protocol and leaves the server half as folklore. What does the authorization server actually do between /authorize and /token? Where do refresh tokens live? What breaks when you rotate signing keys? I wanted to know by building, not by reading.

What got built

A small but complete OIDC ecosystem, five deployable pieces:

  • provider — an authorization server on Spring Authorization Server: registered clients, users, consent, token issuance, JWKS, an admin UI and admin API, Flyway-managed schema.
  • client — a relying-party web app on Spring Security's OAuth2 client: the classic login dance, server-side sessions, Thymeleaf.
  • resource — an edge gateway that validates JWTs it didn't issue: JWKS resolution, route-level authorization, trusted-header propagation, rate limiting.
  • sample-webapp — a "third-party" RP: what an external developer integrating with my IdP actually experiences — login, consent, calling the gateway with the user's token.
  • sample-m2m — machine-to-machine: client_credentials flow end to end.

Plus the plumbing that makes it feel real: a MySQL-backed compose harness for a prod profile, Kubernetes manifests, and an edge design for a cloud application gateway.

What "production-shaped" means here

A toy IdP is a weekend. A convincing one keeps pulling you deeper. The review backlog on this project reads like a real audit:

  • Session-authenticated admin API needed its own stateless security chain — CSRF-off plus cookies is a hole, not a convenience.
  • sub had to move from username to an immutable UUID — mutable subjects are account-confusion bugs waiting for a re-registered username.
  • client_secret_post had to die — secrets in request bodies end up in access logs.
  • Prod cookies needed secure/same-site set in config, not in a README checklist nobody re-reads.

Every one of those is a "oh, that's why the spec says that" moment — the kind you don't get from the client side.

The series

  1. This post — the architecture and the why.
  2. Spring Authorization Server from zero to first login.
  3. The relying party: Spring Security OAuth2 client, Thymeleaf and React variants.
  4. The edge gateway: validating tokens you didn't issue.
  5. Third parties: client_credentials, consent screens, and scope design.
  6. Operating it: health probes, observability, deploy manifests, and the security review that hurt.

Next up: standing up the provider — what Spring Authorization Server hands you for free, and the surprising amount it doesn't.

No comments:

Post a Comment

Java, JavaScript, HTML, XHTML, AJAX, CSS, etc.