Skip to content

Commit 2ec78ff

Browse files
committed
allow state instead of data for signin/out requests
1 parent 8adf360 commit 2ec78ff

File tree

2 files changed

+69
-9
lines changed

2 files changed

+69
-9
lines changed

src/OidcClient.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export default class OidcClient {
3939
}
4040

4141
createSigninRequest({
42-
response_type, scope, redirect_uri, data,
42+
response_type, scope, redirect_uri,
43+
// data was meant to be the place a caller could indiate the data to
44+
// have round tripped, but people were getting confused, so i added state (since that matches the spec)
45+
// and so now if data is not passed, but state is then state will be used
46+
data, state,
4347
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values} = {},
4448
stateStore
4549
) {
@@ -68,15 +72,15 @@ export default class OidcClient {
6872
redirect_uri,
6973
response_type,
7074
scope,
71-
data,
75+
data: data || state,
7276
authority,
7377
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values
7478
});
7579

76-
var state = request.state;
80+
var signinState = request.state;
7781
stateStore = stateStore || this._stateStore;
7882

79-
return stateStore.set(state.id, state.toStorageString()).then(() => {
83+
return stateStore.set(signinState.id, signinState.toStorageString()).then(() => {
8084
return request;
8185
});
8286
});
@@ -107,7 +111,7 @@ export default class OidcClient {
107111
});
108112
}
109113

110-
createSignoutRequest({id_token_hint, data, post_logout_redirect_uri} = {},
114+
createSignoutRequest({id_token_hint, data, state, post_logout_redirect_uri} = {},
111115
stateStore
112116
) {
113117
Log.info("OidcClient.createSignoutRequest");
@@ -126,15 +130,15 @@ export default class OidcClient {
126130
url,
127131
id_token_hint,
128132
post_logout_redirect_uri,
129-
data
133+
data: data || state
130134
});
131135

132-
var state = request.state;
133-
if (state) {
136+
var signoutState = request.state;
137+
if (signoutState) {
134138
Log.info("Signout request has state to persist");
135139

136140
stateStore = stateStore || this._stateStore;
137-
stateStore.set(state.id, state.toStorageString());
141+
stateStore.set(signoutState.id, signoutState.toStorageString());
138142
}
139143

140144
return request;

test/unit/OidcClient.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,43 @@ describe("OidcClient", function () {
149149
});
150150
});
151151

152+
it("should pass state in place of data to SigninRequest", function (done) {
153+
stubMetadataService.getAuthorizationEndpointResult = Promise.resolve("http://sts/authorize");
154+
155+
var p = subject.createSigninRequest({
156+
state: 'foo',
157+
response_type: 'bar',
158+
scope: 'baz',
159+
redirect_uri: 'quux',
160+
prompt: 'p',
161+
display: 'd',
162+
max_age: 'm',
163+
ui_locales: 'u',
164+
id_token_hint: 'ith',
165+
login_hint: 'lh',
166+
acr_values: 'av'
167+
});
168+
169+
p.then(request => {
170+
request.state.data.should.equal('foo');
171+
172+
var url = request.url;
173+
url.should.contain("http://sts/authorize");
174+
url.should.contain("response_type=bar");
175+
url.should.contain("scope=baz");
176+
url.should.contain("redirect_uri=quux");
177+
url.should.contain("prompt=p");
178+
url.should.contain("display=d");
179+
url.should.contain("max_age=m");
180+
url.should.contain("ui_locales=u");
181+
url.should.contain("id_token_hint=ith");
182+
url.should.contain("login_hint=lh");
183+
url.should.contain("acr_values=av");
184+
185+
done();
186+
});
187+
});
188+
152189
it("should fail if metadata fails", function (done) {
153190

154191
stubMetadataService.getAuthorizationEndpointResult = Promise.reject(new Error("test"));
@@ -242,6 +279,25 @@ describe("OidcClient", function () {
242279
});
243280
});
244281

282+
it("should pass state in place of data to SignoutRequest", function (done) {
283+
stubMetadataService.getEndSessionEndpointResult = Promise.resolve("http://sts/signout");
284+
285+
var p = subject.createSignoutRequest({
286+
state: 'foo',
287+
post_logout_redirect_uri: "bar",
288+
id_token_hint: "baz"
289+
});
290+
291+
p.then(request => {
292+
request.state.data.should.equal('foo');
293+
var url = request.url;
294+
url.should.contain("http://sts/signout");
295+
url.should.contain("post_logout_redirect_uri=bar");
296+
url.should.contain("id_token_hint=baz");
297+
done();
298+
});
299+
});
300+
245301
it("should pass params to SignoutRequest", function (done) {
246302
stubMetadataService.getEndSessionEndpointResult = Promise.resolve("http://sts/signout");
247303

0 commit comments

Comments
 (0)