diff --git a/src/models/api/requestModels.js b/src/models/api/requestModels.js index 53257649c9..97d5801eb0 100644 --- a/src/models/api/requestModels.js +++ b/src/models/api/requestModels.js @@ -13,11 +13,11 @@ var FolderRequest = function (folder) { this.name = folder.name ? folder.name.encryptedString : null; }; -var TokenRequest = function (email, masterPasswordHash, token, device) { +var TokenRequest = function (email, masterPasswordHash, provider, token, device) { this.email = email; this.masterPasswordHash = masterPasswordHash; this.token = token; - this.provider = 0; // 0 = Authenticator + this.provider = provider; this.device = null; if (device) { this.device = device; diff --git a/src/popup/app/accounts/accountsLoginController.js b/src/popup/app/accounts/accountsLoginController.js index e40c687322..6fe187c6b0 100644 --- a/src/popup/app/accounts/accountsLoginController.js +++ b/src/popup/app/accounts/accountsLoginController.js @@ -32,10 +32,10 @@ return; } - $scope.loginPromise = authService.logIn(model.email, model.masterPassword, null); + $scope.loginPromise = authService.logIn(model.email, model.masterPassword, null, null); - $scope.loginPromise.then(function (twoFactor) { - if (twoFactor) { + $scope.loginPromise.then(function (response) { + if (response.twoFactor) { $analytics.eventTrack('Logged In To Two-step'); $state.go('twoFactor', { animation: 'in-slide-left', diff --git a/src/popup/app/accounts/accountsLoginTwoFactorController.js b/src/popup/app/accounts/accountsLoginTwoFactorController.js index 025e1146ab..2b814f9808 100644 --- a/src/popup/app/accounts/accountsLoginTwoFactorController.js +++ b/src/popup/app/accounts/accountsLoginTwoFactorController.js @@ -18,7 +18,7 @@ return; } - $scope.loginPromise = authService.logIn(email, masterPassword, model.code); + $scope.loginPromise = authService.logIn(email, masterPassword, 0, model.code); $scope.loginPromise.then(function () { $analytics.eventTrack('Logged In From Two-step'); $state.go('tabs.vault', { animation: 'in-slide-left', syncOnLoad: true }); diff --git a/src/popup/app/services/authService.js b/src/popup/app/services/authService.js index 4c9790db31..1f0cf0f49d 100644 --- a/src/popup/app/services/authService.js +++ b/src/popup/app/services/authService.js @@ -5,14 +5,14 @@ folderService, settingsService, syncService, appIdService, utilsService) { var _service = {}; - _service.logIn = function (email, masterPassword, twoFactorToken) { + _service.logIn = function (email, masterPassword, twoFactorProvider, twoFactorToken) { email = email.toLowerCase(); var key = cryptoService.makeKey(masterPassword, email); var deferred = $q.defer(); cryptoService.hashPassword(masterPassword, key, function (hashedPassword) { appIdService.getAppId(function (appId) { var deviceRequest = new DeviceRequest(appId, utilsService); - var request = new TokenRequest(email, hashedPassword, twoFactorToken, deviceRequest); + var request = new TokenRequest(email, hashedPassword, twoFactorProvider, twoFactorToken, deviceRequest); apiService.postIdentityToken(request, function (response) { // success @@ -27,15 +27,22 @@ cryptoService.setEncKey(response.key).then(function () { return cryptoService.setEncPrivateKey(response.privateKey); }).then(function () { - loggedIn(deferred); + chrome.runtime.sendMessage({ command: 'loggedIn' }); + deferred.resolve({ + twoFactor: false, + twoFactorProviders: null + }); }); }); }); }); }); - }, function () { + }, function (providers) { // two factor required - deferred.resolve(true); + deferred.resolve({ + twoFactor: true, + twoFactorProviders: providers + }); }, function (error) { // error deferred.reject(error); @@ -51,10 +58,5 @@ callback(); }; - function loggedIn(deferred) { - chrome.runtime.sendMessage({ command: 'loggedIn' }); - deferred.resolve(false); - } - return _service; });