1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-02 08:30:14 +01:00

move jwt token to authorization header

This commit is contained in:
Kyle Spearrin 2017-09-14 13:21:00 -04:00
parent be65d5efd4
commit 9ee016251a

View File

@ -118,12 +118,13 @@ function initApiService() {
ApiService.prototype.getAccountRevisionDate = function (success, error) { ApiService.prototype.getAccountRevisionDate = function (success, error) {
log('getAccountRevisionDate invoked'); log('getAccountRevisionDate invoked');
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
log('Revision Date API Call'); log('Revision Date API Call');
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/accounts/revision-date?' + token, url: self.baseUrl + '/accounts/revision-date',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(response); success(response);
}, },
@ -139,11 +140,12 @@ function initApiService() {
ApiService.prototype.getProfile = function (success, error) { ApiService.prototype.getProfile = function (success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/accounts/profile?' + token, url: self.baseUrl + '/accounts/profile',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new ProfileResponse(response)); success(new ProfileResponse(response));
}, },
@ -158,11 +160,12 @@ function initApiService() {
ApiService.prototype.getKeys = function (success, error) { ApiService.prototype.getKeys = function (success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/accounts/keys?' + token, url: self.baseUrl + '/accounts/keys',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new KeysResponse(response)); success(new KeysResponse(response));
}, },
@ -213,11 +216,12 @@ function initApiService() {
ApiService.prototype.getIncludedDomains = function (success, error) { ApiService.prototype.getIncludedDomains = function (success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/settings/domains?excluded=false&' + token, url: self.baseUrl + '/settings/domains?excluded=false',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new DomainsResponse(response)); success(new DomainsResponse(response));
}, },
@ -234,11 +238,12 @@ function initApiService() {
ApiService.prototype.getLogin = function (id, success, error) { ApiService.prototype.getLogin = function (id, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/logins/' + id + '?' + token, url: self.baseUrl + '/logins/' + id,
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new LoginResponse(response)); success(new LoginResponse(response));
}, },
@ -253,13 +258,14 @@ function initApiService() {
ApiService.prototype.postLogin = function (loginRequest, success, error) { ApiService.prototype.postLogin = function (loginRequest, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: self.baseUrl + '/logins?' + token, url: self.baseUrl + '/logins',
data: JSON.stringify(loginRequest), data: JSON.stringify(loginRequest),
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new LoginResponse(response)); success(new LoginResponse(response));
}, },
@ -274,13 +280,14 @@ function initApiService() {
ApiService.prototype.putLogin = function (id, loginRequest, success, error) { ApiService.prototype.putLogin = function (id, loginRequest, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'PUT',
url: self.baseUrl + '/logins/' + id + '?' + token, url: self.baseUrl + '/logins/' + id,
data: JSON.stringify(loginRequest), data: JSON.stringify(loginRequest),
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new LoginResponse(response)); success(new LoginResponse(response));
}, },
@ -297,11 +304,12 @@ function initApiService() {
ApiService.prototype.getFolder = function (id, success, error) { ApiService.prototype.getFolder = function (id, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/folders/' + id + '?' + token, url: self.baseUrl + '/folders/' + id,
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new FolderResponse(response)); success(new FolderResponse(response));
}, },
@ -316,11 +324,12 @@ function initApiService() {
ApiService.prototype.getFolders = function (success, error) { ApiService.prototype.getFolders = function (success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/folders?' + token, url: self.baseUrl + '/folders',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
var data = []; var data = [];
for (var i = 0; i < response.Data.length; i++) { for (var i = 0; i < response.Data.length; i++) {
@ -340,13 +349,14 @@ function initApiService() {
ApiService.prototype.postFolder = function (folderRequest, success, error) { ApiService.prototype.postFolder = function (folderRequest, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: self.baseUrl + '/folders?' + token, url: self.baseUrl + '/folders',
data: JSON.stringify(folderRequest), data: JSON.stringify(folderRequest),
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new FolderResponse(response)); success(new FolderResponse(response));
}, },
@ -361,13 +371,14 @@ function initApiService() {
ApiService.prototype.putFolder = function (id, folderRequest, success, error) { ApiService.prototype.putFolder = function (id, folderRequest, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'PUT',
url: self.baseUrl + '/folders/' + id + '?' + token, url: self.baseUrl + '/folders/' + id,
data: JSON.stringify(folderRequest), data: JSON.stringify(folderRequest),
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new FolderResponse(response)); success(new FolderResponse(response));
}, },
@ -382,11 +393,12 @@ function initApiService() {
ApiService.prototype.deleteFolder = function (id, success, error) { ApiService.prototype.deleteFolder = function (id, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'DELETE',
url: self.baseUrl + '/folders/' + id + '/delete?' + token, url: self.baseUrl + '/folders/' + id,
dataType: 'text', dataType: 'text',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(); success();
}, },
@ -403,11 +415,12 @@ function initApiService() {
ApiService.prototype.getCipher = function (id, success, error) { ApiService.prototype.getCipher = function (id, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/ciphers/' + id + '?' + token, url: self.baseUrl + '/ciphers/' + id,
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new CipherResponse(response)); success(new CipherResponse(response));
}, },
@ -422,11 +435,12 @@ function initApiService() {
ApiService.prototype.getCiphers = function (success, error) { ApiService.prototype.getCiphers = function (success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: self.baseUrl + '/ciphers?includeFolders=false&includeShared=true&' + token, url: self.baseUrl + '/ciphers',
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
var data = []; var data = [];
for (var i = 0; i < response.Data.length; i++) { for (var i = 0; i < response.Data.length; i++) {
@ -446,11 +460,12 @@ function initApiService() {
ApiService.prototype.deleteCipher = function (id, success, error) { ApiService.prototype.deleteCipher = function (id, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'DELETE',
url: self.baseUrl + '/ciphers/' + id + '/delete?' + token, url: self.baseUrl + '/ciphers/' + id,
dataType: 'text', dataType: 'text',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(); success();
}, },
@ -465,14 +480,15 @@ function initApiService() {
ApiService.prototype.postCipherAttachment = function (id, formData, success, error) { ApiService.prototype.postCipherAttachment = function (id, formData, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: self.baseUrl + '/ciphers/' + id + '/attachment?' + token, url: self.baseUrl + '/ciphers/' + id + '/attachment',
data: formData, data: formData,
processData: false, processData: false,
contentType: false, contentType: false,
dataType: 'json', dataType: 'json',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(new CipherResponse(response)); success(new CipherResponse(response));
}, },
@ -487,11 +503,12 @@ function initApiService() {
ApiService.prototype.deleteCipherAttachment = function (id, attachmentId, success, error) { ApiService.prototype.deleteCipherAttachment = function (id, attachmentId, success, error) {
var self = this; var self = this;
handleTokenState(self).then(function (token) { handleTokenState(self).then(function (tokenHeader) {
$.ajax({ $.ajax({
type: 'POST', type: 'DELETE',
url: self.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId + '/delete?' + token, url: self.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId,
dataType: 'text', dataType: 'text',
headers: tokenHeader,
success: function (response) { success: function (response) {
success(); success();
}, },
@ -584,7 +601,9 @@ function initApiService() {
function resolveTokenQs(token, deferred) { function resolveTokenQs(token, deferred) {
log('Resolving token.'); log('Resolving token.');
deferred.resolve('access_token3=' + token); deferred.resolve({
'Authorization': 'Bearer ' + token
});
} }
function log(msg) { function log(msg) {