get private key if not available during sync
This commit is contained in:
parent
f04908058f
commit
154427a0f3
|
@ -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;
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue