Self-hosted OAuth2 provider written in TypeScript using Fastify and Prisma.
- OAuth2 Authorization Code Flow
- JWT-based tokens (Access & Refresh)
- Redis session storage
- PostgreSQL via Prisma ORM
- REST API with Fastify
- Cookie & Session support
- Built-in logging (
pino
) - Environment validation (
envalid
) - Type-safe models using
zod
Layer | Technology |
---|---|
Runtime | Node.js >= 22 |
Framework | Fastify |
ORM | Prisma |
DB | PostgreSQL |
Session | Redis + Fastify Session |
Auth | JWT + OAuth2 |
Logging | Pino |
Validation | Envalid + Zod |
npm run dev # Start dev server with hot reload
npm run build # Build TypeScript to dist/
npm start # Run compiled app from dist/
npm run prisma::migrate # Create and apply migrations
npm run prisma::generate # Generate Prisma client
npm run prisma::pull # Pull DB schema into Prisma schema
Create .env
file:
PORT=3000
NODE_ENV=development
DATABASE_URL="postgresql://user:password@localhost:5432/dbname"
REDIS_HOST=localhost
REDIS_PORT=6379
JWT_SECRET=mysecretkey
SESSION_SECRET=session_secret_key
OAUTH_REDIRECT_URI="http://localhost:3000/oauth/callback"
.
├── source/ # Source code
├── prisma/ # Prisma schema & migrations
├── build/ # Compiled TS output
├── .env # Environment config
└── README.md
-
Install dependencies:
npm install
-
Pull database schema:
npm run prisma::pull
-
Generate Prisma client:
npm run prisma::generate
-
Migrate database:
npm run prisma::migrate
-
Start dev server:
npm run dev
npm test
BSD 2-Clause License