Skip to content

Commit fcd0f8b

Browse files
Merge pull request #224 from TomWeps/master
State improvements
2 parents 9a3a4b6 + 874e96d commit fcd0f8b

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

angular-oauth2-oidc/src/auth.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ export class AuthConfig {
207207
* Normally, the discovey document's url starts with the url of the issuer.
208208
*/
209209
public skipIssuerCheck? = false;
210+
211+
/*
212+
* final state sent to issuer is built as follows:
213+
* state = nonce + nonceStateSeparator + additional state
214+
* Default separator is ';' (encoded %3B).
215+
* In rare cases, this character might be forbidden or inconvenient to use by the issuer so it can be customized.
216+
*/
217+
public nonceStateSeparator? = ';';
218+
210219

211220
constructor(json?: Partial<AuthConfig>) {
212221
if (json) {

angular-oauth2-oidc/src/oauth-service.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ export class OAuthService
942942
return this.createAndSaveNonce().then((nonce: any) => {
943943

944944
if (state) {
945-
state = nonce + ';' + state;
945+
state = nonce + this.config.nonceStateSeparator + state;
946946
}
947947
else {
948948
state = nonce;
@@ -1116,6 +1116,16 @@ export class OAuthService
11161116

11171117
this.debug('parsed url', parts);
11181118

1119+
let state = decodeURIComponent(parts['state']);
1120+
let nonceInState = state;
1121+
let idx = state.indexOf(this.config.nonceStateSeparator);
1122+
1123+
if ( idx > -1) {
1124+
nonceInState = state.substr(0, idx);
1125+
this.state = state.substr(idx + this.config.nonceStateSeparator.length);
1126+
}
1127+
1128+
11191129
if (parts['error']) {
11201130
this.debug('error trying to login');
11211131
this.handleLoginError(options, parts);
@@ -1125,8 +1135,7 @@ export class OAuthService
11251135
}
11261136

11271137
let accessToken = parts['access_token'];
1128-
let idToken = parts['id_token'];
1129-
let state = decodeURIComponent(parts['state']);
1138+
let idToken = parts['id_token'];
11301139
let sessionState = parts['session_state'];
11311140
let grantedScopes = parts['scope'];
11321141

@@ -1145,20 +1154,6 @@ export class OAuthService
11451154
+ 'does not contain a session_state claim');
11461155
}
11471156

1148-
let nonceInState = state;
1149-
let idx = state.indexOf(';');
1150-
1151-
if (idx > -1) {
1152-
nonceInState = state.substr(0, idx);
1153-
this.state = state.substr(idx + 1);
1154-
}
1155-
/*
1156-
let stateParts = state.split(';');
1157-
if (stateParts.length > 1) {
1158-
this.state = stateParts[1];
1159-
}
1160-
*/
1161-
// let nonceInState = stateParts[0];
11621157

11631158
if (this.requestAccessToken && !options.disableOAuth2StateCheck) {
11641159
let success = this.validateNonceForAccessToken(accessToken, nonceInState);

0 commit comments

Comments
 (0)