A simple full-stack authentication application demonstrating multiple login methods using Passport.js with database-driven configuration.
- Username/Password Authentication (Local Strategy)
- Google OAuth 2.0
- OpenID Connect (OIDC)
- SAML SSO
- Database-Driven Configuration - Update auth providers without restarting
- Dynamic Strategy Initialization
- React Frontend with TypeScript
- Node.js/Express Backend with TypeScript
- SQLite Database
- CONFIGURATION.md - Complete guide for managing authentication providers
- CHANGES.md - Details about the database-driven configuration approach
passport-js/
├── backend/ # Node.js + Express + TypeScript
│ ├── src/
│ │ ├── config/ # Database & Passport configuration
│ │ ├── models/ # User & Client models
│ │ ├── routes/ # Authentication & API routes
│ │ ├── strategies/ # Passport strategies
│ │ └── middleware/ # Auth middleware
│ └── package.json
└── frontend/ # React + TypeScript + Vite
├── src/
│ ├── components/ # Login & Signup forms
│ ├── pages/ # Login, Signup, Home pages
│ └── utils/ # API utilities
└── package.json
-
Navigate to the backend directory:
cd backend -
Install dependencies:
npm install
-
Create a
.envfile (copy from.env.example):cp .env.example .env
-
Start the backend server:
npm run dev
The backend will run on
http://localhost:3001Note: On first run with
SEED_DB=true, the database will be seeded with example configurations for Google, OIDC, and SAML. You'll need to update these via the API with your actual credentials.
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The frontend will run on
http://localhost:5173
- Open your browser and go to
http://localhost:5173 - Create an account using username/password (local authentication)
- Login and see "Hello, {user}" on the home page
All authentication provider configurations are stored in the database and can be managed via API calls:
curl http://localhost:3001/api/clientscurl -X POST http://localhost:3001/api/clients \
-H "Content-Type: application/json" \
-d '{
"name": "Google OAuth",
"auth_type": "google",
"config": {
"clientId": "your-google-client-id.apps.googleusercontent.com",
"clientSecret": "your-google-client-secret",
"callbackUrl": "http://localhost:3001/auth/google/callback"
}
}'curl -X POST http://localhost:3001/api/clients \
-H "Content-Type: application/json" \
-d '{
"name": "OpenID Connect",
"auth_type": "oidc",
"config": {
"issuer": "https://your-oidc-provider.com",
"clientId": "your-oidc-client-id",
"clientSecret": "your-oidc-client-secret",
"callbackUrl": "http://localhost:3001/auth/oidc/callback",
"scope": "openid email profile"
}
}'curl -X POST http://localhost:3001/api/clients \
-H "Content-Type: application/json" \
-d '{
"name": "SAML SSO",
"auth_type": "saml",
"config": {
"entryPoint": "https://your-saml-provider.com/sso",
"issuer": "passport-saml",
"callbackUrl": "http://localhost:3001/auth/saml/callback",
"cert": "your-saml-certificate"
}
}'Once configured, the authentication buttons will work for the respective providers.
POST /auth/signup- Create a new local accountPOST /auth/login- Login with username/passwordGET /auth/google- Initiate Google OAuth flowGET /auth/google/callback- Google OAuth callbackGET /auth/oidc- Initiate OIDC flowGET /auth/oidc/callback- OIDC callbackGET /auth/saml- Initiate SAML flowPOST /auth/saml/callback- SAML callbackPOST /auth/logout- Logout current user
GET /api/user- Get current authenticated userGET /api/clients- Get all client configurationsGET /api/clients/:auth_type- Get a specific client configuration by auth typePOST /api/clients- Create or update client configuration (automatically reinitializes the strategy)GET /api/strategies/initialized- Get list of currently initialized authentication strategies
id- Primary keyemail- User emailpassword- Hashed password (for local strategy)provider- Authentication provider (local, google, oidc, saml)provider_id- External provider user IDcreated_at- Timestamp
id- Primary keyname- Client nameauth_type- Authentication type (google, oidc, saml)config- JSON configuration for the auth typecreated_at- Timestampupdated_at- Timestamp
- This is a POC (Proof of Concept) - not production ready
- Session-based authentication using express-session
- SQLite database (auth.db) will be created automatically
- CORS is configured for local development
- All OAuth/OIDC/SAML configurations are stored in the database, not in environment variables
- Passport strategies are dynamically initialized from database configurations
- When you update a client configuration via API, the strategy is automatically reinitialized
- Auth routes check if strategies are initialized before allowing authentication
Backend:
cd backend
npm run dev # Start with hot reload
npm run build # Build for production
npm start # Run production buildFrontend:
cd frontend
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build