The identity server you run yourself
OpenID Connect and OAuth 2.0 for your apps and APIs, on your domain and your database. Accounts, two-factor, consent and an admin for your apps, shipped as one Docker image with a Helm chart.
- OpenID Connect and OAuth 2.0
- Self-hosted
- Free in production
{
"issuer": "https://auth.example.com",
"authorization_endpoint": "https://auth.example.com/api/auth/oauth2/authorize",
"token_endpoint": "https://auth.example.com/api/auth/oauth2/token",
"pushed_authorization_request_endpoint": "https://auth.example.com/api/auth/oauth2/par",
"userinfo_endpoint": "https://auth.example.com/api/auth/oauth2/userinfo",
"jwks_uri": "https://auth.example.com/jwks",
"scopes_supported": ["openid", "profile", "email", "offline_access"],
"grant_types_supported": ["authorization_code", "client_credentials", "refresh_token"],
"code_challenge_methods_supported": ["S256"],
"backchannel_logout_supported": true
}- Signed ID tokens, keys at /jwks
- RS256
- PKCE, required for every sign-in
- S256
- Access and ID tokens
- 10 min
- Refresh tokens, rotated on each use
- 30 days
Identity you control
Your users, your apps and your keys stay on infrastructure you run
An identity provider you can read, change and deploy like the rest of your stack, with the standards your apps already speak.
Sign-in that's yours
Your domain, your name and logo, your database. Passwords, magic links, two-factor and the providers you choose, on pages your users recognise.
Secure before you configure
PKCE on every sign-in, rotating refresh tokens, hashed secrets, rate limits and a strict CSP from the first start, with tests that hold them in place.
Every app, one identity
Web apps and single-page apps sign people in with OIDC, services get client credentials, and your APIs get JWTs meant for them alone.
Why Auth Server
The control of building it yourself, without building it yourself
No lock-in, no licence keys
MIT licensed and free in production, with no per-user pricing. It runs on your Postgres, behind your ingress, and your users' accounts never leave it.
Standards first
OpenID Connect discovery, the authorization code flow with PKCE, pushed authorization requests (RFC 9126), RFC 8707 resource tokens and back-channel logout. Any standard OIDC client library connects without custom code.
Built to change
A Next.js app on Better Auth, in small features with boundaries the linter enforces. Add a sign-in step, a provider or a claim the same way the existing ones were written.
A short way to production
A few commands run it locally next to an example app. A multi-arch image with provenance and an SBOM, a Helm chart, migrations as a pre-sync job, and traces and metrics over OpenTelemetry take it the rest of the way.
Everything included
Everything between “Sign in” and a verified ID token, nothing sold separately
Social sign-in, two-factor, API tokens, back-channel logout and bot protection aren't add-ons or paid tiers: they're in the image, on when you set their keys.
Sign-in, done properly
Email and password, magic links and resets, plus Google, Microsoft, GitHub or your own OIDC provider when you set their keys.
Two-factor
Authenticator apps with backup codes. Turning it on or off, and new codes, each ask for the password first.
Account security
Change the password, see every device that's signed in, and sign out one of them or all of them.
OpenID Connect
Authorization code with PKCE, pushed authorization requests, rotating refresh tokens, discovery, a consent screen and token revocation.
Tokens for your APIs
JWT access tokens for each API you list (RFC 8707), with your own scopes, only for the apps you linked to it.
Services, too
Client credentials for jobs and queue consumers, each limited to the scopes its client was given.
Sign out everywhere
When a session ends, every app that holds a token for it gets a signed back-channel logout token.
An admin for your apps
Register clients on the admin page, or declare them in a file and run one command. Secrets are hashed and shown once.
Shared session
One sign-in across your subdomains, through a session cookie on the parent domain, for the apps you trust.
Bot protection
Cloudflare Turnstile on every form and on the endpoints behind them. On when its two keys are set, off otherwise.
Rate limits
Per client IP on sign-in, sign-up, codes, tokens and every email, behind a proxy you name.
Themes
Light, dark or the system's, six color themes from nuvui, and moving gradients on the sign-in pages.
Preview
The screens your users see
Built from nuvui components, in the theme you pick. Try the palette at the top of the page: these follow it, as the real pages do.
Auth Server
Sign in
Use your Auth Server account.
How it works
Standard OpenID Connect, start to finish
The authorization code flow with PKCE, and nothing else. No implicit flow, no client credentials, no tokens in a URL. Any OIDC client library speaks it.
- 1
Your app sends them here
A redirect to /authorize with a PKCE challenge, a state and a nonce. The app was registered once, by an admin.
GET /api/auth/oauth2/authorize - 2
They sign in
A password or a magic link, then a code from their authenticator app if two-factor is on. Already signed in? Skipped.
/login · /two-factor - 3
They allow the app
The consent screen lists what the app asked for, in words. Allow and they're sent back with a one-time code.
/consent - 4
Your app swaps the code
A POST with the code and the PKCE verifier returns an RS256 ID token, an access token and a refresh token.
POST /api/auth/oauth2/token - 5
Verify, and you're in
Check the ID token against the public keys, and its nonce. Ask /userinfo for the profile when you need it.
GET /jwks · GET …/userinfo
Quick start
Running on your machine in five minutes
Four steps, each with the commands to copy. The example app signs in through the server both ways: the shared cookie and the full OIDC flow.
- 1
Clone and install
Node.js 26 and pnpm. One install for the whole monorepo.
Terminalgit clone https://github.com/sajanv88/authserver-oidc.git cd authserver-oidc pnpm install - 2
Configure
Copy the example and fill in the secrets. The app checks every setting when it starts, and says which one is wrong.
Terminalcp .env.example .env # Then set, in .env: # DATABASE_URL a Postgres 17 database # BETTER_AUTH_SECRET openssl rand -base64 32 # SEED_ADMIN_PASSWORD 12 characters or more # EXAMPLE_SESSION_SECRET openssl rand -base64 32 - 3
Create the database
Tables from the committed migrations, then an admin and the example app as a client. Put the client ID it prints in EXAMPLE_CLIENT_ID.
Terminaldocker compose up -d # or use your own Postgres pnpm db:migrate pnpm db:seed - 4
Run it
Emails are printed in the terminal instead of sent. *.localtest.me always points at your own machine.
Terminalpnpm dev # auth server http://auth.localtest.me:3000 # example app http://app.localtest.me:3001
Connect an app
Four snippets from zero to a signed-in user
Use your framework's OIDC library, or follow these by hand. The example client does all of it in a few hundred lines, refresh and sign-out included.
Register the app in /admin/clients with its redirect URI. Most libraries need only these: the rest comes from discovery.
OIDC_ISSUER=https://auth.example.com
OIDC_CLIENT_ID=your-client-id
# Empty for a public client: PKCE only
OIDC_CLIENT_SECRET=
OIDC_REDIRECT_URI=https://app.example.com/oidc/callback
OIDC_SCOPES="openid profile email offline_access"Tokens for your own APIs
Optional. Your APIs get JWT access tokens they check themselves (RFC 8707), your services get client credentials, and signing out of one app signs out of all of them.
List your APIs in OAUTH_RESOURCES and their scopes in OAUTH_API_SCOPES, then declare your apps in a file. pnpm clients:provision clients.json creates them, updates them on the next run, and prints each new secret once.
{
"clients": [
{
"type": "web",
"name": "Dashboard",
"redirectUris": ["https://app.example.com/api/auth/callback"],
"backchannelLogoutUri": "https://app.example.com/api/auth/backchannel-logout",
"firstParty": true,
"scopes": ["crm"],
"resources": ["https://api.example.com"]
},
{
"type": "machine",
"name": "Nightly jobs",
"scopes": ["crm"],
"resources": ["https://api.example.com"]
}
]
}Endpoints
Every path is on your issuer, such as https://auth.example.com.
| Endpoint | What it's for |
|---|---|
GET/.well-known/openid-configuration | Discovery: every endpoint below, for your library |
GET/jwks | The public keys ID tokens are signed with (RS256) |
GET/api/auth/oauth2/authorize | Starts a sign-in: code + PKCE S256 |
POST/api/auth/oauth2/par | Pushes a sign-in's parameters first (PAR): a one-time request_uri for /authorize |
POST/api/auth/oauth2/token | A code, a refresh token or client credentials for tokens |
GET/api/auth/oauth2/userinfo | The signed-in user's claims |
POST/api/auth/oauth2/revoke | Revokes a token, on sign-out |
POST/api/auth/oauth2/introspect | Whether a token is still active |
GET/api/auth/oauth2/end-session | Signs the user out here too, from an app that signs them out |
Security
Careful by default, so you don't have to be
The decisions an identity provider gets wrong most often are made for you, and covered by tests that drive the real configuration over HTTP.
PKCE on every sign-in
S256 only, no implicit flow, no dynamic registration: an admin adds each app, and links it to the APIs it may call.
Secrets you can't leak
Client secrets are stored hashed and shown once. A spent refresh token revokes its whole family.
Signed requests between steps
An app's request is signed as it moves from sign-in to two-factor to consent, and expires after 10 minutes.
A strict Content Security Policy
A fresh nonce and strict-dynamic on every page, form-action 'self', and the usual security headers.
Nothing to learn from an answer
Sign-up, reset and magic links answer the same whether or not an email exists.
Checked on the server, every time
Every server action checks the session and validates its input, and every redirect is checked.
Rate limits, per client IP
| Endpoint | Allowed |
|---|---|
/sign-in/email | 5 a minute |
/sign-up/email | 3 a minute |
/two-factor/* | 5 a minute |
/request-password-reset | 3 in 5 minutes |
/reset-password | 5 in 5 minutes |
/send-verification-email | 3 in 5 minutes |
/sign-in/magic-link | 3 in 5 minutes |
/magic-link/verify | 10 a minute |
/change-password | 5 in 5 minutes |
/sign-in/social | 10 a minute |
/callback/* | 10 a minute |
/oauth2/token | 30 a minute |
/oauth2/par | 30 a minute |
Everything else | 100 a minute |
Deploy
From a tag to production with Helm and Argo CD
Tag a release and the image and the chart are published to GitHub's registry. Create one Secret, set your domain, and sync.
One image, built once
ghcr.io/sajanv88/auth-server for amd64 and arm64, with provenance and an SBOM. A release retags it; it's never rebuilt.
Migrations before each rollout
An Argo CD PreSync Job runs the bundled migrator from the same image, against your managed Postgres.
Locked down
Non-root, read-only root filesystem, every capability dropped. Secrets come from a Secret you create.
Ready for traffic
Probes on /api/health, autoscaling, a disruption budget, pods spread across nodes, and OpenTelemetry.
kubectl create secret generic auth-server-secrets \
--from-literal=BETTER_AUTH_SECRET="$(openssl rand -base64 32)" \
--from-literal=DATABASE_URL='postgres://user:password@db.internal:5432/auth' \
--from-literal=SMTP_PASSWORD='your-smtp-token'Every merge to main publishes :sha-<commit> and :main; a tag vX.Y.Z adds :vX.Y.Z, :latest and the chart at oci://ghcr.io/sajanv88/charts/auth-server.
Built with
A codebase you'd want to work in
Small features with clear boundaries, enforced by the linter. Every change runs lint, types, unit tests, a build, a Docker health check and Helm checks before it merges.
- App
- Next.js 16React 19Better Auth 1.7TypeScript 7valibot
- Data
- PostgreSQL 17Drizzle ORMPGlite in tests
- UI
- nuvuiSCSS with BEMCloudflare Turnstile
- Ship
- pnpm and TurborepoDockerHelmArgo CDOpenTelemetry
- Test
- VitestPlaywright with BDD scenariosBiomestylelint
Run your own identity server
Clone it, run it on your machine and sign in to the example app through it. Then connect your own apps, and deploy it with the Helm chart.