Skip to content

Repository files navigation

🚀 OAuth Provider Service (SSO)

Self-hosted OAuth2 provider written in TypeScript using Fastify and Prisma.

📦 Features

  • 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

🧱 Tech Stack

LayerTechnology
RuntimeNode.js >= 22
FrameworkFastify
ORMPrisma
DBPostgreSQL
SessionRedis + Fastify Session
AuthJWT + OAuth2
LoggingPino
ValidationEnvalid + Zod

🛠️ Scripts

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

🔐 Environment Variables

Create .env file:

PORT=3000NODE_ENV=developmentDATABASE_URL="postgresql://user:password@localhost:5432/dbname"REDIS_HOST=localhostREDIS_PORT=6379JWT_SECRET=mysecretkeySESSION_SECRET=session_secret_keyOAUTH_REDIRECT_URI="http://localhost:3000/oauth/callback"

📁 Project Structure

.
├── source/ # Source code
├── prisma/ # Prisma schema & migrations
├── build/ # Compiled TS output
├── .env # Environment config
└── README.md

✅ Development

  1. Install dependencies:

    npm install
  2. Pull database schema:

    npm run prisma::pull
  3. Generate Prisma client:

    npm run prisma::generate
  4. Migrate database:

    npm run prisma::migrate
  5. Start dev server:

    npm run dev

🧪 Testing

npm test

📌 License

BSD 2-Clause License

About

Self-hosted OAuth2 provider written in TypeScript using Fastify and Prisma

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages