feat: Implement NestJS Auth, Users, and Licenses modules
Complete authentication system with JWT, refresh tokens, and TOTP 2FA. Auto-generates license keys on registration (CORR-XXXX-XXXX-XXXX format). JwtStrategy enriches payload with license_id and permissions from roles. Multi-tenant isolation enforced at license access layer. Auth Module: - 9 REST endpoints (login, register, refresh, 2FA setup/verify, profile, password reset) - Argon2 password hashing, TOTP with QR code generation - Public endpoints: login, register, forgot-password, reset-password, validate-key - Authenticated endpoints require JWT Bearer token Users Module: - Admin CRUD for user management (requires users.view permission) - Password fields excluded from all responses Licenses Module: - License lookup with owner authorization - Public key validation endpoint for plugin verification - License key generation via random hex parts All DTOs use class-validator, all controllers documented via Swagger. Custom decorators: @Public(), @CurrentUser(), @RequirePermission(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
33
backend-nest/src/modules/auth/auth.module.ts
Normal file
33
backend-nest/src/modules/auth/auth.module.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { AuthService } from './auth.service';
|
||||
import { JwtStrategy } from './jwt.strategy';
|
||||
import { User } from '../../entities/user.entity';
|
||||
import { License } from '../../entities/license.entity';
|
||||
import { Role } from '../../entities/role.entity';
|
||||
import { TeamMember } from '../../entities/team-member.entity';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => ({
|
||||
secret: configService.get<string>('JWT_SECRET'),
|
||||
signOptions: {
|
||||
expiresIn: configService.get<number>('JWT_ACCESS_EXPIRY_SECONDS', 3600),
|
||||
},
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
TypeOrmModule.forFeature([User, License, Role, TeamMember]),
|
||||
],
|
||||
controllers: [AuthController],
|
||||
providers: [AuthService, JwtStrategy],
|
||||
exports: [AuthService],
|
||||
})
|
||||
export class AuthModule {}
|
||||
Reference in New Issue
Block a user