Skip to content

Commit 71b705c

Browse files
committed
fix(state): passing an url with a querystring as the state, e. g. url?x=1
1 parent 3f44eca commit 71b705c

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

projects/lib/src/oauth-service.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
12531253
const nonce = await this.createAndSaveNonce();
12541254

12551255
if (state) {
1256-
state = nonce + this.config.nonceStateSeparator + state;
1256+
state = nonce + this.config.nonceStateSeparator + encodeURIComponent(state);
12571257
} else {
12581258
state = nonce;
12591259
}
@@ -1461,8 +1461,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14611461
}
14621462
}
14631463

1464-
1465-
14661464
private parseQueryString(queryString: string): object {
14671465
if (!queryString || queryString.length === 0) {
14681466
return {};
@@ -1473,8 +1471,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14731471
}
14741472

14751473
return this.urlHelper.parseQueryString(queryString);
1476-
1477-
14781474
}
14791475

14801476
public tryLoginCodeFlow(options: LoginOptions = null): Promise<void> {

projects/sample/src/app/app.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class AppComponent {
2727
this.oauthService.events
2828
.pipe(filter(e => e.type === 'token_received'))
2929
.subscribe(_ => {
30+
console.debug('state', this.oauthService.state);
3031
this.oauthService.loadUserProfile();
3132
});
3233

@@ -57,7 +58,6 @@ export class AppComponent {
5758
// Optional
5859
this.oauthService.setupAutomaticSilentRefresh();
5960

60-
6161
// Display all events
6262
this.oauthService.events.subscribe(e => {
6363
// tslint:disable-next-line:no-console
@@ -70,7 +70,6 @@ export class AppComponent {
7070
// tslint:disable-next-line:no-console
7171
console.debug('Your session has been terminated!');
7272
});
73-
7473
}
7574

7675
//

projects/sample/src/app/home/home.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class HomeComponent implements OnInit {
3333
await this.oauthService.loadDiscoveryDocument();
3434
sessionStorage.setItem('flow', 'implicit');
3535

36-
this.oauthService.initLoginFlow('/some-state;p1=1;p2=2');
36+
this.oauthService.initLoginFlow('/some-state;p1=1;p2=2?p3=3&p4=4');
3737
// the parameter here is optional. It's passed around and can be used after logging in
3838
}
3939

@@ -56,7 +56,7 @@ export class HomeComponent implements OnInit {
5656
await this.oauthService.loadDiscoveryDocument();
5757
sessionStorage.setItem('flow', 'code');
5858

59-
this.oauthService.initLoginFlow('/some-state;p1=1;p2=2');
59+
this.oauthService.initLoginFlow('/some-state;p1=1;p2=2?p3=3&p4=4');
6060
// the parameter here is optional. It's passed around and can be used after logging in
6161
}
6262

0 commit comments

Comments
 (0)