Skip to content

Commit

Permalink
Update prompt param if it's already provided in the url (fix fo Azure…
Browse files Browse the repository at this point in the history
  • Loading branch information
tamerlan committed Oct 20, 2017
1 parent e3188c3 commit ab4cc99
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/adal.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ var AuthenticationContext = (function () {
// renew happens in iframe, so it keeps javascript context
window.renewStates.push(expectedState);

this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('token', resource) + '&prompt=none';
this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._addOrUpdateUrlQueryStringParameter('prompt', 'none', this._getNavigateUrl('token', resource));
urlNavigate = this._addHintParameters(urlNavigate);

this.registerCallback(expectedState, resource, callback);
Expand All @@ -460,8 +460,8 @@ var AuthenticationContext = (function () {
// renew happens in iframe, so it keeps javascript context
window.renewStates.push(expectedState);

this.verbose('Renew Idtoken Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('id_token', null) + '&prompt=none';
this.verbose('Renew Idtoken Expected state: ' + expectedState);
var urlNavigate = this._addOrUpdateUrlQueryStringParameter('prompt', 'none', this._getNavigateUrl('token', null));
urlNavigate = this._addHintParameters(urlNavigate);

urlNavigate += '&nonce=' + encodeURIComponent(this._idTokenNonce);
Expand All @@ -482,6 +482,23 @@ var AuthenticationContext = (function () {
return regex.test(url);
}

/**
* Adds query parameter to url or update it with the new value
* @ignore
*/
AuthenticationContext.prototype._addOrUpdateUrlQueryStringParameter = function (name, value, url) {
// add parameter if it's
if (!this._urlContainsQueryStringParameter(name, url)) {
url += '&' + name + '=' + value;
} else {
// replace the existing value with the new one
var regex = new RegExp('(' + name + '=)[^\&]+');
url = url.replace( regex , '$1' + value);
}

return url;
}

// Calling _loadFrame but with a timeout to signal failure in loadframeStatus. Callbacks are left
// registered when network errors occur and subsequent token requests for same resource are registered to the pending request
/**
Expand Down Expand Up @@ -604,11 +621,12 @@ var AuthenticationContext = (function () {
var expectedState = this._guid() + '|' + resource;
this.config.state = expectedState;
window.renewStates.push(expectedState);
this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('token', resource) + '&prompt=select_account';
this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('token', resource);
if (extraQueryParameters) {
urlNavigate += encodeURIComponent(extraQueryParameters);
}
urlNavigate = this._addOrUpdateUrlQueryStringParameter('prompt', 'select_account', urlNavigate);

if (claims && (urlNavigate.indexOf("&claims") === -1)) {
urlNavigate += '&claims=' + encodeURIComponent(claims);
Expand Down Expand Up @@ -653,12 +671,14 @@ var AuthenticationContext = (function () {
var expectedState = this._guid() + '|' + resource;
this.config.state = expectedState;
window.renewStates.push(expectedState);
this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('token', resource) + '&prompt=select_account';
this.verbose('Renew token Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('token', resource);
if (extraQueryParameters) {
urlNavigate += encodeURIComponent(extraQueryParameters);
}

urlNavigate = this._addOrUpdateUrlQueryStringParameter('prompt', 'select_account', urlNavigate);

if (claims && (urlNavigate.indexOf("&claims") === -1)) {
urlNavigate += '&claims=' + encodeURIComponent(claims);
}
Expand Down Expand Up @@ -819,7 +839,7 @@ var AuthenticationContext = (function () {
}

return urlNavigate;
}
}

/**
* Creates a user object by decoding the id_token
Expand Down

0 comments on commit ab4cc99

Please sign in to comment.