Files
NestJs-Backend/src/modules/device-fingerprint/device-fingerprint.module.ts
David Melendez b68b44f07e init commit
2026-01-14 22:46:29 +01:00

138 lines
4.1 KiB
TypeScript

/**
* Device Fingerprint Module
*
* Main module for device fingerprinting and trust management functionality.
* Integrates all services, controllers, and entities for browser-based
* device identification and two-factor authentication workflows.
*
* @author David Valera Melendez <david@valera-melendez.de>
* @since February 2025
*/
import { Module, forwardRef } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DeviceFingerprintController } from './device-fingerprint.controller';
import { FingerprintService } from './services/fingerprint.service';
import { DeviceService } from './services/device.service';
import { TwoFactorService } from './services/two-factor.service';
import { TrustedDevice } from './entities/trusted-device.entity';
import { TwoFactorVerification } from './entities/two-factor-verification.entity';
import { AuthModule } from '../auth/auth.module';
import { UserModule } from '../user/user.module';
/**
* Device Fingerprint Module
*
* This module provides comprehensive device fingerprinting capabilities
* including:
* - Browser fingerprint generation and validation
* - Device trust verification and risk assessment
* - Two-factor authentication for new device registration
* - Trusted device management and lifecycle
* - Security monitoring and stale device cleanup
*
* The module integrates with the authentication system to provide
* risk-based authentication and device-level security controls.
*/
@Module({
imports: [
/**
* Configuration module for environment variables
*/
ConfigModule,
/**
* TypeORM entities for device fingerprinting
*
* Registers the database entities needed for storing trusted devices
* and managing two-factor verification workflows.
*/
TypeOrmModule.forFeature([
TrustedDevice,
TwoFactorVerification,
]),
/**
* JWT Module for token operations
*/
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
secret: configService.get<string>('JWT_SECRET'),
signOptions: { expiresIn: '10m' },
}),
inject: [ConfigService],
}),
/**
* Auth Module for authentication services
*/
forwardRef(() => AuthModule),
/**
* User Module for user data operations
*/
UserModule,
],
/**
* Module controllers
*
* REST API controllers that expose device fingerprinting functionality
* to client applications and authentication workflows.
*/
controllers: [
DeviceFingerprintController,
],
/**
* Module services and providers
*
* Core business logic services for device fingerprinting, trust management,
* and two-factor authentication workflows.
*/
providers: [
FingerprintService,
DeviceService,
TwoFactorService,
],
/**
* Exported services
*
* Services exported for use in other modules, particularly the
* authentication module for integrating device trust verification
* into login workflows.
*/
exports: [
FingerprintService,
DeviceService,
TwoFactorService,
],
})
export class DeviceFingerprintModule {
/**
* Module configuration and initialization
*
* The module is designed to be imported into the main application module
* and integrates seamlessly with existing authentication and user management
* systems.
*
* Key integration points:
* - DeviceService.verifyDeviceTrust() for login risk assessment
* - TwoFactorService for new device registration workflows
* - FingerprintService for generating reliable device identifiers
*
* Database requirements:
* - trusted_devices table for storing device fingerprints and metadata
* - two_factor_verifications table for managing 2FA workflows
*
* Dependencies:
* - User entity with relationship to trusted devices
* - JWT authentication for protected endpoints
* - Email/SMS services for 2FA code delivery (configurable)
*/
}