1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-09-29 04:07:39 +02:00

get private key if not available during sync

This commit is contained in:
Kyle Spearrin 2017-04-25 16:23:37 -04:00
parent f04908058f
commit 154427a0f3
3 changed files with 55 additions and 5 deletions

View File

@ -47,6 +47,11 @@ var ProfileResponse = function (response) {
}
};
var KeysResponse = function (response) {
this.privateKey = response.PrivateKey;
this.publicKey = response.PublicKey;
};
var ProfileOrganizationResponse = function (response) {
this.id = response.Id;
this.name = response.Name;

View File

@ -1,8 +1,8 @@
function ApiService(tokenService, appIdService, utilsService, logoutCallback) {
this.baseUrl = 'http://localhost:4000'; // Desktop
//this.baseUrl = 'http://localhost:4000'; // Desktop
//this.baseUrl = 'http://192.168.1.8:4000'; // Desktop external
//this.baseUrl = 'https://preview-api.bitwarden.com'; // Preview
//this.baseUrl = 'https://api.bitwarden.com'; // Production
this.baseUrl = 'https://api.bitwarden.com'; // Production
this.tokenService = tokenService;
this.logoutCallback = logoutCallback;
this.appIdService = appIdService;
@ -78,6 +78,25 @@ function initApiService() {
});
};
ApiService.prototype.getKeys = function (success, error) {
var self = this;
handleTokenState(self).then(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/accounts/keys?access_token2=' + token,
dataType: 'json',
success: function (response) {
success(new KeysResponse(response));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
ApiService.prototype.postPasswordHint = function (request, success, error) {
var self = this;
$.ajax({

View File

@ -85,8 +85,34 @@ function initSyncService() {
var self = this;
self.apiService.getProfile(function (response) {
self.cryptoService.getPrivateKey().then(function (privateKey) {
if (response.organizations && !privateKey) {
self.apiService.getKeys(function (keysResponse) {
if (keysResponse.privateKey) {
self.cryptoService.setEncPrivateKey(keysResponse.privateKey).then(function () {
return self.cryptoService.setOrgKeys(response.organizations);
}, function () {
deferred.reject();
}).then(function () {
deferred.resolve();
}, function () {
deferred.reject();
});
}
else {
deferred.resolve();
}
}, function () {
deferred.reject();
});
}
else {
self.cryptoService.setOrgKeys(response.organizations).then(function () {
deferred.resolve();
}, function () {
deferred.reject();
});
}
});
}, function () {
deferred.reject();
@ -103,7 +129,7 @@ function initSyncService() {
var folders = {};
for (var i = 0; i < response.data.length; i++) {
folders[response.data.id] = new FolderData(response.data[i], userId);
folders[response.data[i].id] = new FolderData(response.data[i], userId);
}
self.folderService.replace(folders, function () {