Skip to content

Commit

Permalink
Merge pull request #105 from engineersamuel/fix
Browse files Browse the repository at this point in the history
Fixing double bearer
  • Loading branch information
engineersamuel authored Aug 7, 2017
2 parents 0cb72bc + 652809a commit a8fa3b7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions dist/uds.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,10 @@ return /******/ (function(modules) { // webpackBootstrap
function getToken() {
if (window.sessionjs && window.sessionjs._state.keycloak.token) {
if (window.sessionjs.isAuthenticated()) {
return 'Bearer ' + window.sessionjs._state.keycloak.token;
} else {
window.sessionjs.login();
return window.sessionjs._state.keycloak.token;
}
}
return '';
return null;
}

var executeUdsAjaxCall = function executeUdsAjaxCall(url, httpMethod) {
Expand All @@ -235,8 +233,10 @@ return /******/ (function(modules) { // webpackBootstrap
type: httpMethod,
method: httpMethod,
beforeSend: function beforeSend(xhr) {
if (getToken() !== '') {
if (getToken()) {
xhr.setRequestHeader('Authorization', 'Bearer ' + getToken());
} else {
console.warn('Could not set JWT token on request, unauthenticated.');
}
},
success: function success(response, status, xhr) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "udsjs",
"version": "1.1.62",
"version": "1.1.63",
"description": "Javascript library to interact with Unified Data Services",
"main": "dist/uds.js",
"directories": {
Expand Down
10 changes: 5 additions & 5 deletions uds.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ function forceTokenRefresh() {
function getToken() {
if (window.sessionjs && window.sessionjs._state.keycloak.token) {
if (window.sessionjs.isAuthenticated()) {
return `Bearer ${window.sessionjs._state.keycloak.token}`;
} else {
window.sessionjs.login();
return window.sessionjs._state.keycloak.token;
}
}
return '';
return null;
}

const executeUdsAjaxCall = function (url, httpMethod) {
Expand All @@ -74,8 +72,10 @@ const executeUdsAjaxCall = function (url, httpMethod) {
type: httpMethod,
method: httpMethod,
beforeSend: function(xhr) {
if(getToken() !== '') {
if(getToken()) {
xhr.setRequestHeader('Authorization', 'Bearer ' + getToken());
} else {
console.warn(`Could not set JWT token on request, unauthenticated.`);
}
},
success: (response, status, xhr) => resolve(xhr.status === 204 ? null : response),
Expand Down

0 comments on commit a8fa3b7

Please sign in to comment.