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) {
|
var ProfileOrganizationResponse = function (response) {
|
||||||
this.id = response.Id;
|
this.id = response.Id;
|
||||||
this.name = response.Name;
|
this.name = response.Name;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
function ApiService(tokenService, appIdService, utilsService, logoutCallback) {
|
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 = 'http://192.168.1.8:4000'; // Desktop external
|
||||||
//this.baseUrl = 'https://preview-api.bitwarden.com'; // Preview
|
//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.tokenService = tokenService;
|
||||||
this.logoutCallback = logoutCallback;
|
this.logoutCallback = logoutCallback;
|
||||||
this.appIdService = appIdService;
|
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) {
|
ApiService.prototype.postPasswordHint = function (request, success, error) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
|
@ -85,8 +85,34 @@ function initSyncService() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.apiService.getProfile(function (response) {
|
self.apiService.getProfile(function (response) {
|
||||||
self.cryptoService.setOrgKeys(response.organizations).then(function () {
|
self.cryptoService.getPrivateKey().then(function (privateKey) {
|
||||||
deferred.resolve();
|
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 () {
|
}, function () {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
|
@ -103,7 +129,7 @@ function initSyncService() {
|
||||||
var folders = {};
|
var folders = {};
|
||||||
|
|
||||||
for (var i = 0; i < response.data.length; i++) {
|
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 () {
|
self.folderService.replace(folders, function () {
|
||||||
|
|
Loading…
Reference in New Issue