Installation
This guide covers the detailed installation and configuration process for Authrim.
System Requirements
| Requirement | Minimum Version |
|---|---|
| Node.js | >= 22.0.0 |
| pnpm | >= 9.0.0 |
| Git | Latest |
| Cloudflare Account | Free tier or higher |
Installation Steps
1. Clone and Install
# Clone the repositorygit clone https://github.com/sgrastar/authrim.gitcd authrim
# Install dependenciespnpm install
# Login to Cloudflarewrangler login2. Generate Cryptographic Keys
Generate the RSA keys used for JWT signing:
./scripts/setup-keys.shThis creates:
| File | Purpose |
|---|---|
.keys/private.pem | RSA private key for JWT signing |
.keys/public.jwk.json | Public key in JWK format |
.keys/metadata.json | Key ID and metadata |
3. Configure Environment Variables
# Create .dev.vars with environment variables./scripts/setup-local-vars.sh
# Generate wrangler.toml for local development./scripts/setup-local-wrangler.sh4. Set Up Cloudflare Resources
KV Namespaces
./scripts/setup-kv.sh --env=devThis creates the following KV namespaces:
CLIENTS- OAuth client registrationsSETTINGS- System configurationSTATE_STORE- Authorization codes and stateNONCE_STORE- Replay protection
D1 Database
./scripts/setup-d1.shCreates the authrim-db D1 database for:
- User accounts
- Session data
- Audit logs
Durable Objects
./scripts/setup-durable-objects.shDeploys Durable Objects for:
KeyManager- Cryptographic key managementAuthorizationCodeStore- Auth code storage with strong consistencySessionStore- Session managementRefreshTokenRotator- Refresh token rotation
5. Optional: Configure Email (Resend)
For magic link authentication:
./scripts/setup-resend.sh --env=localWithout Resend, magic links return URLs instead of sending emails (useful for development).
Project Structure
authrim/├── packages/│ ├── shared/ # Shared utilities, types, Durable Objects│ ├── op-discovery/ # Discovery & JWKS endpoints│ ├── op-auth/ # Authorization & consent│ ├── op-token/ # Token endpoint│ ├── op-userinfo/ # UserInfo endpoint│ ├── op-management/ # Admin API & client registration│ ├── op-async/ # Device Flow & CIBA│ ├── op-saml/ # SAML IdP/SP│ ├── scim/ # SCIM 2.0 provisioning│ ├── policy-core/ # Policy engine core│ ├── policy-service/ # Policy evaluation service│ ├── external-idp/ # External IdP integration│ ├── router/ # Unified router (test/dev)│ └── ui/ # SvelteKit frontend├── scripts/ # Setup & deployment scripts├── migrations/ # D1 database migrations├── conformance/ # OpenID conformance testing└── docs/ # DocumentationWorker Architecture
| Worker | Purpose | Endpoints |
|---|---|---|
| op-discovery | OIDC Discovery | /.well-known/* |
| op-auth | Authorization | /authorize, /consent |
| op-token | Token issuance | /token, /introspect, /revoke |
| op-userinfo | User info | /userinfo |
| op-management | Admin API | /api/admin/*, /register |
| op-async | Async flows | /device_authorization, /bc-authorize |
| scim | User provisioning | /scim/v2/* |
| router | Request routing | All (development only) |
Available Scripts
Development
pnpm run dev # Start all workers with hot reloadpnpm run build # Build all packagespnpm run build:api # Build API workers only (exclude UI)Testing
pnpm run test # Run unit testspnpm run test:e2e # Run E2E tests (Playwright)pnpm run test:e2e:ui # Run E2E tests with UIpnpm run test:lighthouse # Run Lighthouse performance testsCode Quality
pnpm run lint # Run ESLintpnpm run typecheck # TypeScript type checkingpnpm run format # Format code with Prettierpnpm run format:check # Check code formattingDeployment
pnpm run deploy # Deploy workers with retry logicpnpm run deploy:ui # Deploy UI to Cloudflare Pagespnpm run deploy:all # Deploy everythingConformance Testing
pnpm run conformance:basic # Run Basic OP testspnpm run conformance:config # Run Config OP testspnpm run conformance:dynamic # Run Dynamic OP testspnpm run conformance:fapi2 # Run FAPI 2.0 testspnpm run conformance:all # Run all conformance testsTroubleshooting
Port 8787 already in use
# Kill the process using the portlsof -ti:8787 | xargs kill -9
# Or use a different portwrangler dev --port 8788KV namespace not found
wrangler kv namespace list./scripts/setup-kv.sh --env=devPrivate key not found
./scripts/setup-keys.sh./scripts/setup-local-vars.shTypeScript errors
pnpm run typecheckView logs
# Developmentwrangler dev --log-level debug
# Productionwrangler tail --env productionNext Steps
- Deployment Guide - Deploy to production
- OIDC Configuration - Configure OpenID Connect
- API Reference - Explore the API