diff --git a/src/modules/multi-factor-authentication/multi-factor-authentication.controller.ts b/src/modules/multi-factor-authentication/multi-factor-authentication.controller.ts index 1047b257d..c5492b9df 100644 --- a/src/modules/multi-factor-authentication/multi-factor-authentication.controller.ts +++ b/src/modules/multi-factor-authentication/multi-factor-authentication.controller.ts @@ -9,7 +9,7 @@ import { import { users } from '@prisma/client'; import { Expose } from 'src/modules/prisma/prisma.interface'; import { Scopes } from '../auth/scope.decorator'; -import { EnableTwoFactorAuthenticationDto } from './multi-factor-authentication.dto'; +import { EnableTotpMfaDto } from './multi-factor-authentication.dto'; import { MultiFactorAuthenticationService } from './multi-factor-authentication.service'; @Controller('users/:userId/multi-factor-authentication') @@ -18,29 +18,25 @@ export class MultiFactorAuthenticationController { private multiFactorAuthenticationService: MultiFactorAuthenticationService, ) {} - @Post('2fa') - @Scopes('user-{userId}:write-2fa') + @Post('totp') + @Scopes('user-{userId}:write-totp') async enable2FA( @Param('userId', ParseIntPipe) userId: number, - @Body() body: EnableTwoFactorAuthenticationDto, + @Body() body: EnableTotpMfaDto, ): Promise | string> { if (body.token) - return this.multiFactorAuthenticationService.enableTwoFactorAuthentication( + return this.multiFactorAuthenticationService.enableTotpMfa( userId, body.token, ); - return this.multiFactorAuthenticationService.requestTwoFactorAuthentication( - userId, - ); + return this.multiFactorAuthenticationService.requestTotpMfa(userId); } - @Delete('2fa') - @Scopes('user-{userId}:delete-2fa') + @Delete('totp') + @Scopes('user-{userId}:delete-totp') async disable2FA( @Param('userId', ParseIntPipe) userId: number, ): Promise> { - return this.multiFactorAuthenticationService.disableTwoFactorAuthentication( - userId, - ); + return this.multiFactorAuthenticationService.disableTotpMfa(userId); } } diff --git a/src/modules/multi-factor-authentication/multi-factor-authentication.dto.ts b/src/modules/multi-factor-authentication/multi-factor-authentication.dto.ts index bb25e6ac9..53c5a6336 100644 --- a/src/modules/multi-factor-authentication/multi-factor-authentication.dto.ts +++ b/src/modules/multi-factor-authentication/multi-factor-authentication.dto.ts @@ -1,6 +1,6 @@ import { IsOptional, IsString } from 'class-validator'; -export class EnableTwoFactorAuthenticationDto { +export class EnableTotpMfaDto { @IsString() @IsOptional() token?: string; diff --git a/src/modules/multi-factor-authentication/multi-factor-authentication.service.ts b/src/modules/multi-factor-authentication/multi-factor-authentication.service.ts index 1ddc8da55..38939c86e 100644 --- a/src/modules/multi-factor-authentication/multi-factor-authentication.service.ts +++ b/src/modules/multi-factor-authentication/multi-factor-authentication.service.ts @@ -8,7 +8,7 @@ import { PrismaService } from '../prisma/prisma.service'; export class MultiFactorAuthenticationService { constructor(private prisma: PrismaService, private auth: AuthService) {} - async requestTwoFactorAuthentication(userId: number): Promise { + async requestTotpMfa(userId: number): Promise { const enabled = await this.prisma.users.findOne({ where: { id: userId }, select: { twoFactorEnabled: true }, @@ -20,14 +20,11 @@ export class MultiFactorAuthenticationService { return this.auth.getTotpQrCode(userId); } - async enableTwoFactorAuthentication( - userId: number, - token: string, - ): Promise> { + async enableTotpMfa(userId: number, token: string): Promise> { return this.auth.enableTotp(userId, token); } - async disableTwoFactorAuthentication(userId: number): Promise> { + async disableTotpMfa(userId: number): Promise> { const enabled = await this.prisma.users.findOne({ where: { id: userId }, select: { twoFactorEnabled: true },