]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/server-commands/users/two-factor-command.ts
Allow admins to disable two factor auth
[github/Chocobozzz/PeerTube.git] / shared / server-commands / users / two-factor-command.ts
index 6c9d270aed8309fcd70c62629968d132a3a309a2..5542acfdad994a99883e4431ff42bdd73353da33 100644 (file)
@@ -21,7 +21,7 @@ export class TwoFactorCommand extends AbstractCommand {
 
   request (options: OverrideCommandOptions & {
     userId: number
-    currentPassword: string
+    currentPassword?: string
   }) {
     const { currentPassword, userId } = options
 
@@ -58,7 +58,7 @@ export class TwoFactorCommand extends AbstractCommand {
 
   disable (options: OverrideCommandOptions & {
     userId: number
-    currentPassword: string
+    currentPassword?: string
   }) {
     const { userId, currentPassword } = options
     const path = '/api/v1/users/' + userId + '/two-factor/disable'
@@ -72,4 +72,21 @@ export class TwoFactorCommand extends AbstractCommand {
       defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
     })
   }
+
+  async requestAndConfirm (options: OverrideCommandOptions & {
+    userId: number
+    currentPassword?: string
+  }) {
+    const { userId, currentPassword } = options
+
+    const { otpRequest } = await this.request({ userId, currentPassword })
+
+    await this.confirmRequest({
+      userId,
+      requestToken: otpRequest.requestToken,
+      otpToken: TwoFactorCommand.buildOTP({ secret: otpRequest.secret }).generate()
+    })
+
+    return otpRequest
+  }
 }