π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add support for validating 2FA
Neeraj Guptad442dff14a4e
diff --git a/cmd/version.go b/cmd/version.goindex 7568a68b4c..cb4d1cf47c 100644--- a/cmd/version.go+++ b/cmd/version.go@@ -13,8 +13,6 @@ var versionCmd = &cobra.Command{Long: ``,Run: func(cmd *cobra.Command, args []string) {fmt.Printf("ente-cli version %s\n", AppVersion)- // increcement counter flag-},}diff --git a/internal/api/login.go b/internal/api/login.goindex 8067384fc3..cb6180cc6b 100644--- a/internal/api/login.go+++ b/internal/api/login.go@@ -134,3 +134,30 @@ func (c *Client) VerifyEmail(}return &res, nil}++func (c *Client) VerifyTotp(+ ctx context.Context,+ sessionID string,+ otp string,+) (*AuthorizationResponse, error) {+ var res AuthorizationResponse+ payload := map[string]interface{}{+ "sessionID": sessionID,+ "code": otp,+ }+ r, err := c.restClient.R().+ SetContext(ctx).+ SetResult(&res).+ SetBody(payload).+ Post("/users/two-factor/verify")+ if err != nil {+ return nil, err+ }+ if r.IsError() {+ return nil, &ApiError{+ StatusCode: r.StatusCode(),+ Message: r.String(),+ }+ }+ return &res, nil+}diff --git a/pkg/account.go b/pkg/account.goindex b859871247..8c80609104 100644--- a/pkg/account.go+++ b/pkg/account.go@@ -59,11 +59,8 @@ func (c *ClICtrl) AddAccount(cxt context.Context) {if flowErr != nil {return}- if authResponse == nil {- return- }if authResponse.IsMFARequired() {-+ authResponse, flowErr = c.validateTOTP(cxt, authResponse)}if keyEncKey == nil {pass, flowErr := GetSensitiveField("Enter password")diff --git a/pkg/sign_in.go b/pkg/sign_in.goindex d66c6fbad7..7507e8cebf 100644--- a/pkg/sign_in.go+++ b/pkg/sign_in.go@@ -46,5 +46,23 @@ func (c *ClICtrl) signInViaPassword(ctx context.Context, email string, srpAttr *}return authResp, keyEncKey, nil}+}+func (c *ClICtrl) validateTOTP(ctx context.Context, authResp *api.AuthorizationResponse) (*api.AuthorizationResponse, error) {+ if !authResp.IsMFARequired() {+ return authResp, nil+ }+ for {+ // CLI prompt for TOTP+ totp, flowErr := GetCode("Enter TOTP", 6)+ if flowErr != nil {+ return nil, flowErr+ }+ totpResp, err := c.Client.VerifyTotp(ctx, authResp.TwoFactorSessionID, totp)+ if err != nil {+ log.Printf("failed to verify %v", err)+ continue+ }+ return totpResp, nil+ }}