This project demonstrates Single Sign-On (SSO) using Node.js and Authentik with OpenID Connect (OIDC).
sequenceDiagram
participant User as User
participant App as Node.js App
participant Authentik as Authentik
User->>App: Visit /login
App->>Authentik: Redirect to authorization endpoint
Authentik-->>User: Show login page
User->>Authentik: Enter credentials
Authentik-->>App: Redirect to /callback with code
App->>Authentik: Exchange code for tokens
Authentik-->>App: Return access/id tokens
App->>App: Create user session
App-->>User: Redirect to home page
- Express.js web server
- Passport.js for authentication
- OpenID Connect integration with Authentik
- Session management
- TypeScript support
- Node.js (v20 or higher)
- pnpm
- Authentik instance (self-hosted or cloud)
pnpm install- In your Authentik instance, create a new Application
- Create a Provider of type "OpenID Connect"
- Set the redirect URI to
http://localhost:3000/callback - Note down:
- Client ID
- Client Secret
- Issuer URL (e.g.,
https://your-authentik-instance/application/o/nodejs-sso-sample/)
Create a .env file in the root directory:
PORT=3000
AUTHENTIK_ISSUER_URL=https://your-authentik-instance/application/o/nodejs-sso-sample/
AUTHENTIK_CLIENT_ID=your-client-id
AUTHENTIK_CLIENT_SECRET=your-client-secret
SESSION_SECRET=your-session-secret-keypnpm devThe server will start at http://localhost:3000
/- Home page/login- Initiate SSO login/callback- OIDC callback URL/profile- User profile (protected)/logout- Logout
pnpm test- Node.js
- Express.js
- Passport.js
- passport-openidconnect
- TypeScript
- tsx
- Vitest