Identity Service

NestJS:8016Core

The Identity Service handles user authentication, account management, and JWT token operations. It supports dual database mode (MSSQL + MongoDB) and can run as both HTTP server and RabbitMQ worker.

Architecture

Identity Service Architecture

Loading diagram...

Key Features

  • User Authentication — Login, logout, password management
  • JWT Token Management — Access tokens (1h), refresh tokens (7d), S2S tokens
  • Account Management — User creation, updates, deactivation
  • SSO Integration — OpenAM Single Sign-On support
  • OTP — One-time password generation and verification (5min TTL)
  • Push Notifications — Firebase (Android) and APNs (iOS) device registration
  • Dual Mode — HTTP API + RabbitMQ worker mode

API Endpoints

POST
/api/identity/login

Authenticate user and return JWT tokens

POST
/api/identity/refresh-token

Refresh access token using refresh token

POST
/api/identity/logout

Invalidate session and tokens

POST
/api/identity/register

Register new user account

POST
/api/identity/otp/generate

Generate one-time password

POST
/api/identity/otp/verify

Verify one-time password

GET
/api/identity/users/:id

Get user details by ID

PUT
/api/identity/users/:id

Update user account

Configuration

NameTypeDefaultDescription
PORTnumber8016Service listening port
DB_HOSTstringlocalhostMSSQL server host
DB_USERNAMEstring-Database username
DB_PASSWORDstring-Database password
MONGO_URIstring-MongoDB connection string
JWT_SECRETstring-JWT signing secret
JWT_ACCESS_EXPIRYstring1hAccess token expiration
JWT_REFRESH_EXPIRYstring7dRefresh token expiration
REDIS_HOSTstringlocalhostRedis host
RABBITMQ_URISstring-RabbitMQ connection URIs

RabbitMQ Integration

Publishes to:

  • identity_events exchange — User lifecycle events
  • session_manager exchange — Session created/destroyed events

Consumes from:

  • OTP request queue — Processes OTP generation requests

Database

  • MSSQL — User account data, role mappings
  • MongoDB — Credentials, device tokens, flexible user metadata

Dependencies

  • Media Service — Excel/PDF generation for user exports
  • Redis — Token caching, session storage