@@ -23,14 +23,7 @@ export class MultiFactorAuthenticationController {
2323 private multiFactorAuthenticationService : MultiFactorAuthenticationService ,
2424 ) { }
2525
26- @Post ( 'regenerate' )
27- @Scopes ( 'user-{userId}:write-mfa-regenerate' )
28- async regenerateBackupCodes (
29- @Param ( 'userId' , ParseIntPipe ) userId : number ,
30- ) : Promise < string [ ] > {
31- return this . multiFactorAuthenticationService . regenerateBackupCodes ( userId ) ;
32- }
33-
26+ /** Disable MFA for a user */
3427 @Delete ( )
3528 @Scopes ( 'user-{userId}:delete-mfa-*' )
3629 async disable2FA (
@@ -39,53 +32,70 @@ export class MultiFactorAuthenticationController {
3932 return this . multiFactorAuthenticationService . disableMfa ( userId ) ;
4033 }
4134
35+ /** Regenerate backup codes for a user */
36+ @Post ( 'regenerate' )
37+ @Scopes ( 'user-{userId}:write-mfa-regenerate' )
38+ async regenerateBackupCodes (
39+ @Param ( 'userId' , ParseIntPipe ) userId : number ,
40+ ) : Promise < string [ ] > {
41+ return this . multiFactorAuthenticationService . regenerateBackupCodes ( userId ) ;
42+ }
43+
44+ /** Enable TOTP-based MFA for a user */
4245 @Post ( 'totp' )
4346 @Scopes ( 'user-{userId}:write-mfa-totp' )
4447 async enableTotp (
4548 @Param ( 'userId' , ParseIntPipe ) userId : number ,
4649 @Body ( ) body : EnableTotpMfaDto ,
47- ) : Promise < string [ ] | string > {
50+ ) : Promise < string [ ] | { img : string } > {
4851 if ( body . token )
4952 return this . multiFactorAuthenticationService . enableMfa (
5053 'TOTP' ,
5154 userId ,
5255 body . token ,
5356 ) ;
54- return this . multiFactorAuthenticationService . requestTotpMfa ( userId ) ;
57+ return {
58+ img : await this . multiFactorAuthenticationService . requestTotpMfa ( userId ) ,
59+ } ;
5560 }
5661
62+ /** Enable SMS-based MFA for a user */
5763 @Post ( 'sms' )
5864 @Scopes ( 'user-{userId}:write-mfa-sms' )
5965 async enableSms (
6066 @Param ( 'userId' , ParseIntPipe ) userId : number ,
6167 @Body ( ) body : EnableSmsMfaDto ,
62- ) : Promise < string [ ] | void > {
68+ ) : Promise < string [ ] | { success : true } > {
6369 if ( body . token )
6470 return this . multiFactorAuthenticationService . enableMfa (
6571 'SMS' ,
6672 userId ,
6773 body . token ,
6874 ) ;
69- if ( body . phone )
70- return this . multiFactorAuthenticationService . requestSmsMfa (
75+ if ( body . phone ) {
76+ await this . multiFactorAuthenticationService . requestSmsMfa (
7177 userId ,
7278 body . phone ,
7379 ) ;
80+ return { success : true } ;
81+ }
7482 throw new BadRequestException ( MFA_PHONE_OR_TOKEN_REQUIRED ) ;
7583 }
7684
85+ /** Enable email-based MFA for a user */
7786 @Post ( 'email' )
7887 @Scopes ( 'user-{userId}:write-mfa-email' )
7988 async enableEmail (
8089 @Param ( 'userId' , ParseIntPipe ) userId : number ,
8190 @Body ( ) body : EnableTotpMfaDto ,
82- ) : Promise < string [ ] | void > {
91+ ) : Promise < string [ ] | { success : true } > {
8392 if ( body . token )
8493 return this . multiFactorAuthenticationService . enableMfa (
8594 'EMAIL' ,
8695 userId ,
8796 body . token ,
8897 ) ;
89- return this . multiFactorAuthenticationService . requestEmailMfa ( userId ) ;
98+ await this . multiFactorAuthenticationService . requestEmailMfa ( userId ) ;
99+ return { success : true } ;
90100 }
91101}
0 commit comments