1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

configure u2f device

This commit is contained in:
Kyle Spearrin
2017-06-22 17:02:24 -04:00
parent e366b7c7a7
commit 0135476b68
5 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
angular
.module('bit.settings')
.controller('settingsTwoStepU2fController', function ($scope, apiService, $uibModalInstance, cryptoService,
authService, toastr, $analytics, constants, $timeout, $window) {
$analytics.eventTrack('settingsTwoStepU2fController', { category: 'Modal' });
var _masterPasswordHash;
$scope.deviceResponse = null;
$scope.deviceListening = false;
$scope.deviceError = false;
$scope.auth = function (model) {
_masterPasswordHash = cryptoService.hashPassword(model.masterPassword);
$scope.authPromise = apiService.twoFactor.getU2f({}, {
masterPasswordHash: _masterPasswordHash
}).$promise.then(function (response) {
$scope.enabled = response.Enabled;
$scope.challenge = response.Challenge;
$scope.authed = true;
return $scope.readDevice();
});
};
$scope.readDevice = function () {
$scope.deviceResponse = null;
$scope.deviceError = false;
$scope.deviceListening = true;
$window.u2f.register($scope.challenge.AppId, [{
version: $scope.challenge.Version,
challenge: $scope.challenge.Challenge
}], [], function (data) {
$scope.deviceListening = false;
console.log('call back data:');
console.log(data);
if (data.errorCode) {
$scope.deviceError = true;
$scope.$apply();
console.log('error: ' + data.errorCode);
return;
}
$scope.deviceResponse = JSON.stringify(data);
$scope.$apply();
});
};
$scope.submit = function () {
if ($scope.enabled) {
disable();
return;
}
update();
};
function disable() {
if (!confirm('Are you sure you want to disable the U2F provider?')) {
return;
}
$scope.submitPromise = apiService.twoFactor.disable({}, {
masterPasswordHash: _masterPasswordHash,
type: constants.twoFactorProvider.u2f
}, function (response) {
$analytics.eventTrack('Disabled Two-step U2F');
toastr.success('U2F has been disabled.');
$scope.enabled = response.Enabled;
$scope.close();
}).$promise;
}
function update() {
$scope.submitPromise = apiService.twoFactor.putU2f({}, {
deviceResponse: $scope.deviceResponse,
masterPasswordHash: _masterPasswordHash
}, function (response) {
$analytics.eventTrack('Enabled Two-step U2F');
$scope.enabled = response.Enabled;
$scope.challenge = null;
$scope.deviceResponse = null;
$scope.deviceError = false;
}).$promise;
}
$scope.close = function () {
$uibModalInstance.close($scope.enabled);
};
});