Skip to content

Commit

Permalink
fix(state): passing an url with a querystring as the state, e. g. url…
Browse files Browse the repository at this point in the history
…?x=1
  • Loading branch information
manfredsteyer committed Mar 22, 2020
1 parent 3f44eca commit 71b705c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
const nonce = await this.createAndSaveNonce();

if (state) {
state = nonce + this.config.nonceStateSeparator + state;
state = nonce + this.config.nonceStateSeparator + encodeURIComponent(state);
} else {
state = nonce;
}
Expand Down Expand Up @@ -1461,8 +1461,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
}
}



private parseQueryString(queryString: string): object {
if (!queryString || queryString.length === 0) {
return {};
Expand All @@ -1473,8 +1471,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
}

return this.urlHelper.parseQueryString(queryString);


}

public tryLoginCodeFlow(options: LoginOptions = null): Promise<void> {
Expand Down
3 changes: 1 addition & 2 deletions projects/sample/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class AppComponent {
this.oauthService.events
.pipe(filter(e => e.type === 'token_received'))
.subscribe(_ => {
console.debug('state', this.oauthService.state);
this.oauthService.loadUserProfile();
});

Expand Down Expand Up @@ -57,7 +58,6 @@ export class AppComponent {
// Optional
this.oauthService.setupAutomaticSilentRefresh();


// Display all events
this.oauthService.events.subscribe(e => {
// tslint:disable-next-line:no-console
Expand All @@ -70,7 +70,6 @@ export class AppComponent {
// tslint:disable-next-line:no-console
console.debug('Your session has been terminated!');
});

}

//
Expand Down
4 changes: 2 additions & 2 deletions projects/sample/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class HomeComponent implements OnInit {
await this.oauthService.loadDiscoveryDocument();
sessionStorage.setItem('flow', 'implicit');

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

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

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

Expand Down

0 comments on commit 71b705c

Please sign in to comment.