@@ -135,10 +135,6 @@ var AuthenticationContext = (function () {
135
135
this . _openedWindows = [ ] ;
136
136
this . _requestType = this . REQUEST_TYPE . LOGIN ;
137
137
window . _adalInstance = this ;
138
- this . _storageSupport = {
139
- localStorage : null ,
140
- sessionStorage : null
141
- } ;
142
138
143
139
// validate before constructor assignments
144
140
if ( config . displayCall && typeof config . displayCall !== 'function' ) {
@@ -813,7 +809,6 @@ var AuthenticationContext = (function () {
813
809
* Clears cache items.
814
810
*/
815
811
AuthenticationContext . prototype . clearCache = function ( ) {
816
- this . _user = null ;
817
812
this . _saveItem ( this . CONSTANTS . STORAGE . LOGIN_REQUEST , '' ) ;
818
813
this . _saveItem ( this . CONSTANTS . STORAGE . ANGULAR_LOGIN_REQUEST , '' ) ;
819
814
this . _saveItem ( this . CONSTANTS . STORAGE . SESSION_STATE , '' ) ;
@@ -860,6 +855,7 @@ var AuthenticationContext = (function () {
860
855
*/
861
856
AuthenticationContext . prototype . logOut = function ( ) {
862
857
this . clearCache ( ) ;
858
+ this . _user = null ;
863
859
var urlNavigate ;
864
860
865
861
if ( this . config . logOutUri ) {
@@ -928,8 +924,7 @@ var AuthenticationContext = (function () {
928
924
* @ignore
929
925
*/
930
926
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.
933
928
//If sid is sent alongside domain or login hints, there will be a failure since request is ambiguous.
934
929
//If sid is sent with a prompt value other than none or attempt_none, there will be a failure since the request is ambiguous.
935
930
@@ -1103,7 +1098,7 @@ var AuthenticationContext = (function () {
1103
1098
if ( requestNonce ) {
1104
1099
requestNonce = requestNonce . split ( this . CONSTANTS . CACHE_DELIMETER ) ;
1105
1100
for ( var i = 0 ; i < requestNonce . length ; i ++ ) {
1106
- if ( requestNonce [ i ] === user . profile . nonce ) {
1101
+ if ( requestNonce [ i ] && requestNonce [ i ] === user . profile . nonce ) {
1107
1102
return true ;
1108
1103
}
1109
1104
}
@@ -1122,7 +1117,7 @@ var AuthenticationContext = (function () {
1122
1117
if ( loginStates ) {
1123
1118
loginStates = loginStates . split ( this . CONSTANTS . CACHE_DELIMETER ) ;
1124
1119
for ( var i = 0 ; i < loginStates . length ; i ++ ) {
1125
- if ( loginStates [ i ] === requestInfo . stateResponse ) {
1120
+ if ( loginStates [ i ] && loginStates [ i ] === requestInfo . stateResponse ) {
1126
1121
requestInfo . requestType = this . REQUEST_TYPE . LOGIN ;
1127
1122
requestInfo . stateMatch = true ;
1128
1123
return true ;
@@ -1135,7 +1130,7 @@ var AuthenticationContext = (function () {
1135
1130
if ( acquireTokenStates ) {
1136
1131
acquireTokenStates = acquireTokenStates . split ( this . CONSTANTS . CACHE_DELIMETER ) ;
1137
1132
for ( var i = 0 ; i < acquireTokenStates . length ; i ++ ) {
1138
- if ( acquireTokenStates [ i ] === requestInfo . stateResponse ) {
1133
+ if ( acquireTokenStates [ i ] && acquireTokenStates [ i ] === requestInfo . stateResponse ) {
1139
1134
requestInfo . requestType = this . REQUEST_TYPE . RENEW_TOKEN ;
1140
1135
requestInfo . stateMatch = true ;
1141
1136
return true ;
@@ -1218,16 +1213,17 @@ var AuthenticationContext = (function () {
1218
1213
this . _user = null ;
1219
1214
} else {
1220
1215
this . _saveItem ( this . CONSTANTS . STORAGE . IDTOKEN , requestInfo . parameters [ this . CONSTANTS . ID_TOKEN ] ) ;
1216
+
1221
1217
// 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 ;
1223
1219
1224
- if ( ! this . _hasResource ( idTokenResource ) ) {
1220
+ if ( ! this . _hasResource ( resource ) ) {
1225
1221
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 ) ;
1227
1223
}
1228
1224
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 ) ;
1231
1227
}
1232
1228
}
1233
1229
else {
@@ -1689,7 +1685,7 @@ var AuthenticationContext = (function () {
1689
1685
ifr . setAttribute ( 'aria-hidden' , 'true' ) ;
1690
1686
ifr . style . visibility = 'hidden' ;
1691
1687
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' ;
1693
1689
1694
1690
adalFrame = document . getElementsByTagName ( 'body' ) [ 0 ] . appendChild ( ifr ) ;
1695
1691
}
@@ -1764,52 +1760,37 @@ var AuthenticationContext = (function () {
1764
1760
} ;
1765
1761
1766
1762
/**
1767
- * Returns true if the browser supports given storage type
1763
+ * Returns true if browser supports localStorage, false otherwise.
1768
1764
* @ignore
1769
1765
*/
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 ( ) {
1779
1767
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
1793
1774
} catch ( e ) {
1794
- this . _storageSupport [ storageType ] = false ;
1775
+ return false ;
1795
1776
}
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' ) ;
1805
1777
} ;
1806
1778
1807
1779
/**
1808
1780
* Returns true if browser supports sessionStorage, false otherwise.
1809
1781
* @ignore
1810
1782
*/
1811
1783
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
+ }
1813
1794
} ;
1814
1795
1815
1796
/**
@@ -1955,4 +1936,4 @@ var AuthenticationContext = (function () {
1955
1936
1956
1937
return AuthenticationContext ;
1957
1938
1958
- } ( ) ) ;
1939
+ } ( ) ) ;
0 commit comments