Skip to content

Commit 07af544

Browse files
committed
only use state and post_logout_redirect_uri if we have a id_token_hint on signout
1 parent 016cfd5 commit 07af544

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/SignoutRequest.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ export default class SignoutRequest {
1212
throw new Error("url");
1313
}
1414

15-
if (data) {
16-
this.state = new State({ data });
17-
url = UrlUtility.addQueryParam(url, "state", this.state.id);
18-
}
19-
2015
if (id_token_hint) {
2116
url = UrlUtility.addQueryParam(url, "id_token_hint", id_token_hint);
17+
18+
if (post_logout_redirect_uri) {
19+
url = UrlUtility.addQueryParam(url, "post_logout_redirect_uri", post_logout_redirect_uri);
20+
21+
if (data) {
22+
this.state = new State({ data });
23+
24+
url = UrlUtility.addQueryParam(url, "state", this.state.id);
25+
}
26+
}
2227
}
23-
if (post_logout_redirect_uri) {
24-
url = UrlUtility.addQueryParam(url, "post_logout_redirect_uri", post_logout_redirect_uri);
25-
}
28+
2629
this.url = url;
2730
}
2831
}

test/unit/OidcClient.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe("OidcClient", function () {
4545
authority: 'authority',
4646
client_id: 'client',
4747
redirect_uri: "http://app",
48+
post_logout_redirect_uri: "http://app",
4849
stateStore: stubStore,
4950
ResponseValidatorCtor: () => stubValidator,
5051
MetadataServiceCtor: () => stubMetadataService
@@ -275,7 +276,7 @@ describe("OidcClient", function () {
275276
stubMetadataService.getEndSessionEndpointResult = Promise.resolve("http://sts/signout");
276277

277278
var p = subject.createSignoutRequest({
278-
data:"foo"
279+
data:"foo", id_token_hint:'hint'
279280
});
280281

281282
p.then(request => {

test/unit/SignoutRequest.spec.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,32 @@ describe("SignoutRequest", function() {
4545
subject.url.indexOf("http://sts/signout").should.equal(0);
4646
});
4747

48-
it("should include state", function() {
49-
subject.url.should.contain("state=" + subject.state.id);
50-
});
51-
5248
it("should include id_token_hint", function() {
5349
subject.url.should.contain("id_token_hint=hint");
5450
});
5551

56-
it("should include post_logout_redirect_uri", function() {
52+
it("should include post_logout_redirect_uri if id_token_hint also provided", function() {
5753
subject.url.should.contain("post_logout_redirect_uri=loggedout");
5854
});
55+
56+
it("should not include post_logout_redirect_uri if no id_token_hint provided", function() {
57+
58+
delete settings.id_token_hint;
59+
subject = new SignoutRequest(settings);
60+
61+
subject.url.should.not.contain("post_logout_redirect_uri=loggedout");
62+
});
63+
64+
it("should include state if post_logout_redirect_uri provided", function() {
65+
subject.url.should.contain("state=" + subject.state.id);
66+
});
67+
68+
it("should not include state if no post_logout_redirect_uri provided", function() {
69+
delete settings.post_logout_redirect_uri;
70+
subject = new SignoutRequest(settings);
71+
subject.url.should.not.contain("state=");
72+
});
73+
5974

6075
it("should include id_token_hint, post_logout_redirect_uri, and state", function() {
6176
var url = subject.url;

0 commit comments

Comments
 (0)