@@ -843,9 +843,9 @@ export class OAuthService extends AuthConfig {
843
843
this . setupSilentRefreshEventListener ( ) ;
844
844
845
845
const redirectUri = this . silentRefreshRedirectUri || this . redirectUri ;
846
- this . createLoginUrl ( null , null , redirectUri , noPrompt , params ) . then ( url => {
846
+ this . createLoginUrl ( null , redirectUri , noPrompt , params ) . then ( url => {
847
847
iframe . setAttribute ( 'src' , url ) ;
848
-
848
+
849
849
if ( ! this . silentRefreshShowIFrame ) {
850
850
iframe . style [ 'display' ] = 'none' ;
851
851
}
@@ -1054,7 +1054,6 @@ export class OAuthService extends AuthConfig {
1054
1054
}
1055
1055
1056
1056
private createLoginUrl (
1057
- state = '' ,
1058
1057
loginHint = '' ,
1059
1058
customRedirectUri = '' ,
1060
1059
noPrompt = false ,
@@ -1071,12 +1070,6 @@ export class OAuthService extends AuthConfig {
1071
1070
}
1072
1071
1073
1072
return this . createAndSaveNonce ( ) . then ( ( nonce : any ) => {
1074
- if ( state ) {
1075
- state = nonce + this . config . nonceStateSeparator + state ;
1076
- } else {
1077
- state = nonce ;
1078
- }
1079
-
1080
1073
if ( ! this . requestAccessToken && ! this . oidc ) {
1081
1074
throw new Error (
1082
1075
'Either requestAccessToken or oidc or both must be true'
@@ -1107,7 +1100,7 @@ export class OAuthService extends AuthConfig {
1107
1100
'&client_id=' +
1108
1101
encodeURIComponent ( that . clientId ) +
1109
1102
'&state=' +
1110
- encodeURIComponent ( state ) +
1103
+ encodeURIComponent ( nonce ) +
1111
1104
'&redirect_uri=' +
1112
1105
encodeURIComponent ( redirectUri ) +
1113
1106
'&scope=' +
@@ -1170,7 +1163,11 @@ export class OAuthService extends AuthConfig {
1170
1163
addParams = params ;
1171
1164
}
1172
1165
1173
- this . createLoginUrl ( additionalState , loginHint , null , false , addParams )
1166
+ if ( additionalState ) {
1167
+ this . storeAdditionalState ( additionalState ) ;
1168
+ }
1169
+
1170
+ this . createLoginUrl ( loginHint , null , false , addParams )
1174
1171
. then ( function ( url ) {
1175
1172
location . href = url ;
1176
1173
} )
@@ -1181,6 +1178,10 @@ export class OAuthService extends AuthConfig {
1181
1178
} ) ;
1182
1179
}
1183
1180
1181
+ private storeAdditionalState ( additionalState : string ) {
1182
+ localStorage . setItem ( 'additionalState' , additionalState ) ;
1183
+ }
1184
+
1184
1185
/**
1185
1186
* Starts the implicit flow and redirects to user to
1186
1187
* the auth servers login url.
@@ -1261,16 +1262,9 @@ export class OAuthService extends AuthConfig {
1261
1262
this . debug ( 'parsed url' , parts ) ;
1262
1263
1263
1264
const state = parts [ 'state' ] ;
1264
- let nonceInState = state ;
1265
-
1266
- if ( state ) {
1267
- const idx = state . indexOf ( this . config . nonceStateSeparator ) ;
1265
+ const nonceInState = state ;
1268
1266
1269
- if ( idx > - 1 ) {
1270
- nonceInState = state . substr ( 0 , idx ) ;
1271
- this . state = state . substr ( idx + this . config . nonceStateSeparator . length ) ;
1272
- }
1273
- }
1267
+ this . updateStateWithStoredAdditionalStateIfExists ( ) ;
1274
1268
1275
1269
if ( parts [ 'error' ] ) {
1276
1270
this . debug ( 'error trying to login' ) ;
@@ -1372,6 +1366,13 @@ export class OAuthService extends AuthConfig {
1372
1366
} ) ;
1373
1367
}
1374
1368
1369
+ private updateStateWithStoredAdditionalStateIfExists ( ) {
1370
+ const additionalState = localStorage . getItem ( 'additionalState' ) ;
1371
+ if ( additionalState ) {
1372
+ this . state = additionalState ;
1373
+ }
1374
+ }
1375
+
1375
1376
private validateNonceForAccessToken (
1376
1377
accessToken : string ,
1377
1378
nonceInState : string
0 commit comments