Skip to content

Commit 74158db

Browse files
krishardysalvoravida
authored andcommitted
ADAL.js update
1 parent e82bc42 commit 74158db

File tree

1 file changed

+32
-51
lines changed

1 file changed

+32
-51
lines changed

src/adal.js

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ var AuthenticationContext = (function () {
135135
this._openedWindows = [];
136136
this._requestType = this.REQUEST_TYPE.LOGIN;
137137
window._adalInstance = this;
138-
this._storageSupport = {
139-
localStorage: null,
140-
sessionStorage: null
141-
};
142138

143139
// validate before constructor assignments
144140
if (config.displayCall && typeof config.displayCall !== 'function') {
@@ -813,7 +809,6 @@ var AuthenticationContext = (function () {
813809
* Clears cache items.
814810
*/
815811
AuthenticationContext.prototype.clearCache = function () {
816-
this._user = null;
817812
this._saveItem(this.CONSTANTS.STORAGE.LOGIN_REQUEST, '');
818813
this._saveItem(this.CONSTANTS.STORAGE.ANGULAR_LOGIN_REQUEST, '');
819814
this._saveItem(this.CONSTANTS.STORAGE.SESSION_STATE, '');
@@ -860,6 +855,7 @@ var AuthenticationContext = (function () {
860855
*/
861856
AuthenticationContext.prototype.logOut = function () {
862857
this.clearCache();
858+
this._user = null;
863859
var urlNavigate;
864860

865861
if (this.config.logOutUri) {
@@ -928,8 +924,7 @@ var AuthenticationContext = (function () {
928924
* @ignore
929925
*/
930926
AuthenticationContext.prototype._addHintParameters = function (urlNavigate) {
931-
932-
//If you don't use prompt=none, then if the session does not exist, there will be a failure.
927+
//If you don�t use prompt=none, then if the session does not exist, there will be a failure.
933928
//If sid is sent alongside domain or login hints, there will be a failure since request is ambiguous.
934929
//If sid is sent with a prompt value other than none or attempt_none, there will be a failure since the request is ambiguous.
935930

@@ -1103,7 +1098,7 @@ var AuthenticationContext = (function () {
11031098
if (requestNonce) {
11041099
requestNonce = requestNonce.split(this.CONSTANTS.CACHE_DELIMETER);
11051100
for (var i = 0; i < requestNonce.length; i++) {
1106-
if (requestNonce[i] === user.profile.nonce) {
1101+
if (requestNonce[i] && requestNonce[i] === user.profile.nonce) {
11071102
return true;
11081103
}
11091104
}
@@ -1122,7 +1117,7 @@ var AuthenticationContext = (function () {
11221117
if (loginStates) {
11231118
loginStates = loginStates.split(this.CONSTANTS.CACHE_DELIMETER);
11241119
for (var i = 0; i < loginStates.length; i++) {
1125-
if (loginStates[i] === requestInfo.stateResponse) {
1120+
if (loginStates[i] && loginStates[i] === requestInfo.stateResponse) {
11261121
requestInfo.requestType = this.REQUEST_TYPE.LOGIN;
11271122
requestInfo.stateMatch = true;
11281123
return true;
@@ -1135,7 +1130,7 @@ var AuthenticationContext = (function () {
11351130
if (acquireTokenStates) {
11361131
acquireTokenStates = acquireTokenStates.split(this.CONSTANTS.CACHE_DELIMETER);
11371132
for (var i = 0; i < acquireTokenStates.length; i++) {
1138-
if (acquireTokenStates[i] === requestInfo.stateResponse) {
1133+
if (acquireTokenStates[i] && acquireTokenStates[i] === requestInfo.stateResponse) {
11391134
requestInfo.requestType = this.REQUEST_TYPE.RENEW_TOKEN;
11401135
requestInfo.stateMatch = true;
11411136
return true;
@@ -1218,16 +1213,17 @@ var AuthenticationContext = (function () {
12181213
this._user = null;
12191214
} else {
12201215
this._saveItem(this.CONSTANTS.STORAGE.IDTOKEN, requestInfo.parameters[this.CONSTANTS.ID_TOKEN]);
1216+
12211217
// Save idtoken as access token for app itself
1222-
var idTokenResource = this.config.loginResource ? this.config.loginResource : this.config.clientId;
1218+
resource = this.config.loginResource ? this.config.loginResource : this.config.clientId;
12231219

1224-
if (!this._hasResource(idTokenResource)) {
1220+
if (!this._hasResource(resource)) {
12251221
keys = this._getItem(this.CONSTANTS.STORAGE.TOKEN_KEYS) || '';
1226-
this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + idTokenResource + this.CONSTANTS.RESOURCE_DELIMETER);
1222+
this._saveItem(this.CONSTANTS.STORAGE.TOKEN_KEYS, keys + resource + this.CONSTANTS.RESOURCE_DELIMETER);
12271223
}
12281224

1229-
this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + idTokenResource, requestInfo.parameters[this.CONSTANTS.ID_TOKEN]);
1230-
this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + idTokenResource, this._user.profile.exp);
1225+
this._saveItem(this.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + resource, requestInfo.parameters[this.CONSTANTS.ID_TOKEN]);
1226+
this._saveItem(this.CONSTANTS.STORAGE.EXPIRATION_KEY + resource, this._user.profile.exp);
12311227
}
12321228
}
12331229
else {
@@ -1689,7 +1685,7 @@ var AuthenticationContext = (function () {
16891685
ifr.setAttribute('aria-hidden', 'true');
16901686
ifr.style.visibility = 'hidden';
16911687
ifr.style.position = 'absolute';
1692-
ifr.style.width = ifr.style.height = ifr.style.borderWidth = '0px';
1688+
ifr.style.width = ifr.style.height = ifr.borderWidth = '0px';
16931689

16941690
adalFrame = document.getElementsByTagName('body')[0].appendChild(ifr);
16951691
}
@@ -1764,52 +1760,37 @@ var AuthenticationContext = (function () {
17641760
};
17651761

17661762
/**
1767-
* Returns true if the browser supports given storage type
1763+
* Returns true if browser supports localStorage, false otherwise.
17681764
* @ignore
17691765
*/
1770-
AuthenticationContext.prototype._supportsStorage = function(storageType) {
1771-
if (!(storageType in this._storageSupport)) {
1772-
return false;
1773-
}
1774-
1775-
if (this._storageSupport[storageType] !== null) {
1776-
return this._storageSupport[storageType];
1777-
}
1778-
1766+
AuthenticationContext.prototype._supportsLocalStorage = function () {
17791767
try {
1780-
if (!(storageType in window) || window[storageType] === null) {
1781-
throw new Error();
1782-
}
1783-
var testKey = '__storageTest__';
1784-
window[storageType].setItem(testKey, 'A');
1785-
if (window[storageType].getItem(testKey) !== 'A') {
1786-
throw new Error();
1787-
}
1788-
window[storageType].removeItem(testKey);
1789-
if (window[storageType].getItem(testKey)) {
1790-
throw new Error();
1791-
}
1792-
this._storageSupport[storageType] = true;
1768+
if (!window.localStorage) return false; // Test availability
1769+
window.localStorage.setItem('storageTest', 'A'); // Try write
1770+
if (window.localStorage.getItem('storageTest') != 'A') return false; // Test read/write
1771+
window.localStorage.removeItem('storageTest'); // Try delete
1772+
if (window.localStorage.getItem('storageTest')) return false; // Test delete
1773+
return true; // Success
17931774
} catch (e) {
1794-
this._storageSupport[storageType] = false;
1775+
return false;
17951776
}
1796-
return this._storageSupport[storageType];
1797-
}
1798-
1799-
/**
1800-
* Returns true if browser supports localStorage, false otherwise.
1801-
* @ignore
1802-
*/
1803-
AuthenticationContext.prototype._supportsLocalStorage = function () {
1804-
return this._supportsStorage('localStorage');
18051777
};
18061778

18071779
/**
18081780
* Returns true if browser supports sessionStorage, false otherwise.
18091781
* @ignore
18101782
*/
18111783
AuthenticationContext.prototype._supportsSessionStorage = function () {
1812-
return this._supportsStorage('sessionStorage');
1784+
try {
1785+
if (!window.sessionStorage) return false; // Test availability
1786+
window.sessionStorage.setItem('storageTest', 'A'); // Try write
1787+
if (window.sessionStorage.getItem('storageTest') != 'A') return false; // Test read/write
1788+
window.sessionStorage.removeItem('storageTest'); // Try delete
1789+
if (window.sessionStorage.getItem('storageTest')) return false; // Test delete
1790+
return true; // Success
1791+
} catch (e) {
1792+
return false;
1793+
}
18131794
};
18141795

18151796
/**
@@ -1955,4 +1936,4 @@ var AuthenticationContext = (function () {
19551936

19561937
return AuthenticationContext;
19571938

1958-
}());
1939+
}());

0 commit comments

Comments
 (0)