KBS Cloud Identity is a custom, lightweight Single Sign-On (SSO) authentication portal designed for games and apps in the KBS ecosystem, such as Star-Swarm and Ticker-Clash.
The system leverages standard OAuth/SSO flows to securely authenticate users, manage active sessions, and issue signed JSON Web Tokens (JWT) for game node verification.
- Dual Login Compatibility: Log in using a standard local email and password, or use Google OAuth.
- Auto-Linking System: Logging in via Google automatically links the OAuth provider with an existing local email account if registered under the same address.
- Password Management for OAuth: Users registered via Google OAuth can create/set a local password, enabling them to optionally sign in using email/password or OAuth. Existing local passwords can be securely changed upon verification of their current password.
- Context-Sensitive Sci-Fi Styling: Automatically switches client themes and branding based on the calling application (e.g. Neon Cyan/Yellow styling for the Star-Swarm Terminal secure command protocols, and Neon Pink/Green styling for the Ticker-Clash trader clearing systems).
- Master SSO Session: Scopes cookies to permit seamless automatic authorization redirects when navigating between different client apps.
- SQLite Storage: Efficient lightweight SQLite datastore managing persistent users, master sessions, and single-use authorization codes.
- Frontend: React 19, TypeScript, Vite, Vanilla CSS (with Custom variables, CSS animations, and glassmorphism styling)
- Backend: Express, SQLite3 (via
sqlite3driver), BcryptJS, Cookie-Parser, JSONWebToken, Google Auth Library - Process Manager: Systemd service integration
+------------------+ +------------------+ +-------------------+
| Game Client | | SSO Portal | | Game Server |
| (e.g. StarSwarm) | | (kbs-auth) | | (Backend Service) |
+--------+---------+ +--------+---------+ +---------+---------+
| | |
| 1. Redirect to /api/authorize | |
|------------------------------>| |
| | |
| 2. User logs in (SSO / OAuth) | |
| | |
| 3. Redirect back with ?code | |
|<------------------------------| |
| | |
| 4. Send auth code to backend | |
|--------------------------------------------------------------->|
| | |
| | 5. Exchange code for JWT |
| | POST /api/auth/token |
| |<-------------------------------|
| | |
| | 6. Respond with identity JWT |
| |------------------------------->|
| |
| 7. User fully authenticated |
|<---------------------------------------------------------------|
GET /api/auth/authorize- Evaluates the master SSO cookie session. If active, redirects with a single-use authorization code; otherwise, redirects the user to the portal login screen.POST /api/auth/token- Backend-to-backend token exchange. Game nodes submit the authorization code and receive the signed JWT identity token.POST /api/auth/login- Local email/password login, generating the master SSO session.POST /api/auth/register- Creates a local user account.GET /api/auth/me- Resolves the current SSO session and returns the user payload (including display name, Google linked status, and password configuration status).POST /api/auth/change-password- Allows changing or creating a local password.GET /api/auth/google&GET /api/auth/callback/google- Initiate and complete Google OAuth 2.0 flow.
- Node.js (v20+ recommended)
- NPM
-
Install project dependencies:
npm install
-
Configure Environment Variables. Ensure the following environment variables are loaded in
/etc/environmentor your environment manager:JWT_SECRET: Secret key for signing identity JWTs.GOOGLE_CLIENT_ID: Google Client ID for OAuth login.GOOGLE_CLIENT_SECRET: Google Client Secret for OAuth login.GOOGLE_CALLBACK_URL: Direct callback URI (e.g.,https://auth.kbs-cloud.com/api/auth/callback/google).PORT: Server port (defaults to3000).
-
Start the Development Server (concurrently spins up the Express API and Vite frontend):
npm run dev
- Open
http://localhost:8080to view the portal. - Vite proxies
/api/*requests automatically to the Express server running on port3000.
- Open
The repository includes an automated deploy.sh script to build and deploy the application locally.
Execute:
./deploy.shThe script automates:
- Frontend compilation (
npm run build). - Staging files inside
/servers/auth. - Installing production node packages (
npm ci --omit=dev). - Writing the Systemd unit configuration (
/etc/systemd/system/kbs-auth.service). - Reloading systemctl daemons and restarting the
kbs-authservice.
This project is licensed under the MIT License - see the LICENSE file for details.