@obelisk/client
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -73,3 +73,10 @@ "use strict"; | ||
let red_uri = loginOptions && loginOptions.redirectUri || window.location.href; | ||
red_uri = red_uri.endsWith('#') ? red_uri.slice(0, -1) : red_uri; | ||
red_uri = red_uri.endsWith('#') ? red_uri.slice(0, red_uri.length - 1) : red_uri; | ||
// Capture queryString if present | ||
const idx = red_uri.indexOf('?'); | ||
let queryString = null; | ||
if (idx !== -1) { | ||
queryString = red_uri.slice(idx); | ||
red_uri = red_uri.slice(0, idx); | ||
} | ||
const prompt = loginOptions && loginOptions.prompt; | ||
@@ -79,3 +86,6 @@ let params = '?'; | ||
params += '&redirect_uri=' + encodeURIComponent(red_uri); | ||
params += '&state=' + encodeURIComponent(this.generateState()); | ||
// In case of queryString, add as state | ||
if (queryString !== null) { | ||
params += '&state=' + encodeURIComponent(btoa(queryString)); | ||
} | ||
params += '&nonce=' + encodeURIComponent(this.generateNonce()); | ||
@@ -344,10 +354,11 @@ params += '&scope=' + encodeURIComponent('openid'); | ||
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; | ||
const hasState = authResponse.state || null; | ||
let params = `code=${authResponse.code}&grant_type=authorization_code`; | ||
if (!this.isStateValid(authResponse.state)) { | ||
console.log('[IoT-CLIENT] Invalid state, clearing token'); | ||
this.clearTokens(); | ||
this.authOver$.next(); | ||
return rxjs_1.of(false); | ||
} | ||
const redUri = window.location.origin + window.location.pathname; | ||
let redUri = window.location.origin + window.location.pathname; | ||
// if (!this.isStateValid(authResponse.state!)) { | ||
// console.log('[IoT-CLIENT] Invalid state, clearing token') | ||
// this.clearTokens(); | ||
// this.authOver$.next(); | ||
// return of(false); | ||
// } | ||
params += '&client_id=' + encodeURIComponent(this._options.clientId); | ||
@@ -387,2 +398,9 @@ params += '&redirect_uri=' + redUri; | ||
this.authOver$.next(); | ||
if (hasState) { | ||
// If modern browser, insert querystring without reload | ||
if (history.pushState) { | ||
const newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + atob(hasState); | ||
window.history.pushState({ path: newurl }, '', newurl); | ||
} | ||
} | ||
return rxjs_1.of(true); | ||
@@ -389,0 +407,0 @@ })); |
{ | ||
"name": "@obelisk/client", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Typescript client to interact with Obelisk on a higher level than the regular ReST API calls.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
106736
2838