fix and update

This commit is contained in:
lendry
2026-06-29 22:51:25 +03:00
parent 885b07d76b
commit 57cb58347b
30 changed files with 799 additions and 187 deletions

View File

@@ -1,8 +1,10 @@
import { Body, Controller, Get, Headers, Ip, Post, UseInterceptors } from '@nestjs/common';
import { Body, Controller, Get, Headers, Post, Req, UseInterceptors } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import type { Request } from 'express';
import { firstValueFrom } from 'rxjs';
import { CoreGrpcService } from '../core-grpc.service';
import { enrichAuthClientMeta } from '../client-request.util';
import { BeginTotpLoginDto, IdentifyDto, LdapLoginDto, LoginDto, PasswordlessOtpDto, PasswordlessVerifyDto, PasswordLoginDto, RefreshSessionDto, RegisterDto, VerifyPinDto, VerifyTotpLoginDto } from '../dto/auth.dto';
import { resolveAuthorizedPayload, verifyAccessToken } from '../session-auth';
import { FedcmCookieInterceptor } from '../interceptors/fedcm-cookie.interceptor';
@@ -26,8 +28,8 @@ export class AuthController {
@Post('login')
@ApiOperation({ summary: 'Вход по почте, телефону или логину', description: 'Возвращает JWT и refresh token. Если PIN включен, сессия создается в ограниченном режиме.' })
@ApiBody({ type: LoginDto })
login(@Body() dto: LoginDto) {
return this.core.auth.Login(dto);
login(@Body() dto: LoginDto, @Req() req: Request) {
return this.core.auth.Login(enrichAuthClientMeta(req, dto));
}
@Post('identify')
@@ -40,29 +42,29 @@ export class AuthController {
@Post('otp/send')
@ApiOperation({ summary: 'Отправить OTP для входа', description: 'Passwordless-first вход: пользователь вводит почту или телефон, сервер создает 6-значный код и пишет его в console.log.' })
@ApiBody({ type: PasswordlessOtpDto })
sendOtp(@Body() dto: PasswordlessOtpDto, @Ip() ipAddress?: string) {
return this.core.auth.SendOtp({ recipient: dto.recipient, channel: dto.channel, ipAddress });
sendOtp(@Body() dto: PasswordlessOtpDto, @Req() req: Request) {
return this.core.auth.SendOtp({ recipient: dto.recipient, channel: dto.channel, ipAddress: enrichAuthClientMeta(req, {}).ipAddress });
}
@Post('otp/verify')
@ApiOperation({ summary: 'Проверить OTP для входа', description: 'Если пользователь не существует, создает его. Если пароль не задан, сразу возвращает JWT. Если пароль задан, возвращает requiresPassword=true и tempAuthToken.' })
@ApiBody({ type: PasswordlessVerifyDto })
verifyOtp(@Body() dto: PasswordlessVerifyDto) {
return this.core.auth.VerifyOtp(dto);
verifyOtp(@Body() dto: PasswordlessVerifyDto, @Req() req: Request) {
return this.core.auth.VerifyOtp(enrichAuthClientMeta(req, dto));
}
@Post('login/password')
@ApiOperation({ summary: 'Войти по паролю', description: 'Identifier-first парольный шаг. Принимает login+password, либо tempAuthToken+password для совместимости, затем выдает JWT.' })
@ApiBody({ type: PasswordLoginDto })
loginWithPassword(@Body() dto: PasswordLoginDto) {
return this.core.auth.LoginWithPassword(dto);
loginWithPassword(@Body() dto: PasswordLoginDto, @Req() req: Request) {
return this.core.auth.LoginWithPassword(enrichAuthClientMeta(req, dto));
}
@Post('ldap/login')
@ApiOperation({ summary: 'Войти через LDAP/LDAPS', description: 'Аутентификация через корпоративный LDAP-сервер. Требует включённой настройки LDAP_ENABLED.' })
@ApiBody({ type: LdapLoginDto })
loginWithLdap(@Body() dto: LdapLoginDto) {
return this.core.auth.LoginWithLdap(dto);
loginWithLdap(@Body() dto: LdapLoginDto, @Req() req: Request) {
return this.core.auth.LoginWithLdap(enrichAuthClientMeta(req, dto));
}
@Post('pin/verify')
@@ -75,15 +77,15 @@ export class AuthController {
@Post('totp/begin')
@ApiOperation({ summary: 'Начать вход по TOTP', description: 'Создаёт challenge для входа через приложение-аутентификатор вместо SMS/email OTP.' })
@ApiBody({ type: BeginTotpLoginDto })
beginTotpLogin(@Body() dto: BeginTotpLoginDto) {
return this.core.auth.BeginTotpLogin(dto);
beginTotpLogin(@Body() dto: BeginTotpLoginDto, @Req() req: Request) {
return this.core.auth.BeginTotpLogin(enrichAuthClientMeta(req, dto));
}
@Post('totp/verify')
@ApiOperation({ summary: 'Подтвердить TOTP при входе', description: 'Завершает вход после проверки кода из Google Authenticator или аналога.' })
@ApiBody({ type: VerifyTotpLoginDto })
verifyTotpLogin(@Body() dto: VerifyTotpLoginDto) {
return this.core.auth.VerifyTotpLogin(dto);
verifyTotpLogin(@Body() dto: VerifyTotpLoginDto, @Req() req: Request) {
return this.core.auth.VerifyTotpLogin(enrichAuthClientMeta(req, dto));
}
@Post('refresh')