How ravikisha/node-sso-gateway works
Project type and purpose
• This is a full-stack, multi-application Single Sign-On (SSO) system.
• Purpose: Provide a central Node.js/Express SSO Server for user authentication (JWT-based, backed by MongoDB) and multiple consumer applications (client1, client2, etc.) that rely on that server for login/session management.
File structure
Top level:
• server/ – the SSO Server
– config/keys – JWT private key
– controller/ – login/register handlers and jwt_helper
– router/ – Express routes (login, register, token-verify)
– views/ – EJS templates for login/register/index
– index.js – main Express app
• client1/, client2/ – identical SSO Consumers
– config/keys – JWT public key
– checkSSORedirect.js – middleware to redirect to SSO Server
– jwt_verify.js – token validation against SSO Server
– isAuthenticated.js – local session guard
– views/ – EJS templates
– index.js – main Express app
Patterns:
– Clear separation of auth service vs. consumers
– Token-based (JWT) stateless interactions
– MVC-like structure in server and clients
– Configuration centralized under config/
Key insights from README
• Central SSO Server issues JWTs after credential validation, stores users in MongoDB.
• Consumers redirect to SSO Server for login, then validate the returned token and establish local sessions.
• Supports dynamic registration of consumer domains via allowedOrigins.
• Emphasis on global vs. local sessions, stateless security.
Main components & interactions
a. Components:
1. Browser (User Agent)
2. SSO Consumer Apps (client1, client2, …)
3. SSO Authorization Server
4. MongoDB Database
b. Interactions / Data flow:
1. User hits a protected route in Consumer → isAuthenticated middleware
2. If no local session → checkSSORedirect → redirect to SSO Server login page
3. User submits credentials to SSO Server → controller.validate() → on success, JWT issued
4. SSO Server redirects back to Consumer with JWT in query or header
5. Consumer’s jwt_verify.js calls SSO Server /verify endpoint → validation
6. On valid token → establish local session → access protected resource
7. All user data reads/writes on SSO Server go to MongoDB (user collection)
c. Architectural patterns / principles:
– Service segregation: Auth service vs. clients
– Stateless tokens for cross-domain auth
– Middleware pipelines for authentication/authorization
– Config-driven allowedOrigins for dynamic consumer onboarding
d. Key technologies:
– Node.js, Express.js (server framework)
– JSON Web Tokens (JWT) for stateless auth
– MongoDB (user store)
– EJS templates for server-side views
– bcrypt for password hashing (in controllers)
Detailed elements to capture
– SSO Server’s internal chain: Express app → router/index.js → controller/jwt_helper → MongoDB
– Consumers’ chain: Express app → checkSSORedirect → jwt_verify → isAuthenticated → views
– Global vs. local session distinction (annotate two session stores or notes)
– allowedOrigins config lookup on the SSO Server before token issuance
– Logout flow: Consumer session clear → call SSO Server logout endpoint → destroy global session