Skip to content

Commit 5fbce7c

Browse files
committed
update for query response type; allow response_type settings param
1 parent 2c2c3d8 commit 5fbce7c

8 files changed

+47
-11
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export interface OidcClientSettings {
123123
client_id?: string;
124124
client_secret?: string;
125125
readonly response_type?: string;
126+
readonly response_mode?: string;
126127
readonly scope?: string;
127128
readonly redirect_uri?: string;
128129
readonly post_logout_redirect_uri?: string;

src/OidcClient.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class OidcClient {
4444
// have round tripped, but people were getting confused, so i added state (since that matches the spec)
4545
// and so now if data is not passed, but state is then state will be used
4646
data, state, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
47-
resource, request, request_uri, extraQueryParams } = {},
47+
resource, request, request_uri, response_mode, extraQueryParams } = {},
4848
stateStore
4949
) {
5050
Log.debug("OidcClient.createSigninRequest");
@@ -61,6 +61,7 @@ export class OidcClient {
6161
ui_locales = ui_locales || this._settings.ui_locales;
6262
acr_values = acr_values || this._settings.acr_values;
6363
resource = resource || this._settings.resource;
64+
response_mode = response_mode || this._settings.response_mode;
6465
extraQueryParams = extraQueryParams || this._settings.extraQueryParams;
6566

6667
let authority = this._settings.authority;
@@ -81,7 +82,7 @@ export class OidcClient {
8182
data: data || state,
8283
authority,
8384
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
84-
resource, request, request_uri, extraQueryParams,
85+
resource, request, request_uri, extraQueryParams, response_mode
8586
});
8687

8788
var signinState = signinRequest.state;
@@ -96,7 +97,12 @@ export class OidcClient {
9697
processSigninResponse(url, stateStore) {
9798
Log.debug("OidcClient.processSigninResponse");
9899

99-
var response = new SigninResponse(url);
100+
let delimiter = "#";
101+
if (this._settings.response_mode === "query" || SigninRequest.isCode(this._settings.response_type)) {
102+
delimiter = "?";
103+
}
104+
105+
var response = new SigninResponse(url, delimiter);
100106

101107
if (!response.state) {
102108
Log.error("OidcClient.processSigninResponse: No state in response");

src/OidcClientSettings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class OidcClientSettings {
2121
client_id, client_secret, response_type = DefaultResponseType, scope = DefaultScope,
2222
redirect_uri, post_logout_redirect_uri,
2323
// optional protocol
24-
prompt, display, max_age, ui_locales, acr_values, resource,
24+
prompt, display, max_age, ui_locales, acr_values, resource, response_mode,
2525
// behavior flags
2626
filterProtocolClaims = true, loadUserInfo = true,
2727
staleStateAge = DefaultStaleStateAge, clockSkew = DefaultClockSkewInSeconds,
@@ -51,6 +51,7 @@ export class OidcClientSettings {
5151
this._ui_locales = ui_locales;
5252
this._acr_values = acr_values;
5353
this._resource = resource;
54+
this._response_mode = response_mode;
5455

5556
this._filterProtocolClaims = !!filterProtocolClaims;
5657
this._loadUserInfo = !!loadUserInfo;
@@ -114,6 +115,9 @@ export class OidcClientSettings {
114115
get resource() {
115116
return this._resource;
116117
}
118+
get response_mode() {
119+
return this._response_mode;
120+
}
117121

118122

119123
// metadata

src/SigninRequest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class SigninRequest {
1010
// mandatory
1111
url, client_id, redirect_uri, response_type, scope, authority,
1212
// optional
13-
data, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource,
13+
data, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, response_mode,
1414
request, request_uri, extraQueryParams,
1515
}) {
1616
if (!url) {
@@ -54,10 +54,9 @@ export class SigninRequest {
5454
if (code) {
5555
url = UrlUtility.addQueryParam(url, "code_challenge", this.state.code_challenge);
5656
url = UrlUtility.addQueryParam(url, "code_challenge_method", "S256");
57-
url = UrlUtility.addQueryParam(url, "response_mode", "fragment");
5857
}
5958

60-
var optional = { prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, request, request_uri };
59+
var optional = { prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, request, request_uri, response_mode };
6160
for(let key in optional){
6261
if (optional[key]) {
6362
url = UrlUtility.addQueryParam(url, key, optional[key]);

src/SigninResponse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { UrlUtility } from './UrlUtility';
66
const OidcScope = "openid";
77

88
export class SigninResponse {
9-
constructor(url) {
9+
constructor(url, delimiter = "#") {
1010

11-
var values = UrlUtility.parseUrlFragment(url, "#");
11+
var values = UrlUtility.parseUrlFragment(url, delimiter);
1212

1313
this.error = values.error;
1414
this.error_description = values.error_description;

test/unit/OidcClient.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe("OidcClient", function () {
120120
var p = subject.createSigninRequest({
121121
data: 'foo',
122122
response_type: 'bar',
123+
response_mode: 'mode',
123124
scope: 'baz',
124125
redirect_uri: 'quux',
125126
prompt: 'p',
@@ -152,6 +153,7 @@ describe("OidcClient", function () {
152153
url.should.contain("resource=res");
153154
url.should.contain("request=req");
154155
url.should.contain("request_uri=req_uri");
156+
url.should.contain("response_mode=mode");
155157

156158
done();
157159
});

test/unit/OidcClientSettings.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ describe("OidcClientSettings", function () {
163163
});
164164
});
165165

166+
describe("resource", function () {
167+
it("should return value from initial settings", function () {
168+
let subject = new OidcClientSettings({
169+
client_id: 'client',
170+
resource: "foo"
171+
});
172+
subject.resource.should.equal("foo");
173+
});
174+
});
175+
176+
describe("response_mode", function () {
177+
it("should return value from initial settings", function () {
178+
let subject = new OidcClientSettings({
179+
client_id: 'client',
180+
response_mode: "foo"
181+
});
182+
subject.response_mode.should.equal("foo");
183+
});
184+
});
185+
166186
describe("authority", function () {
167187
it("should return value from initial settings", function () {
168188
let subject = new OidcClientSettings({

test/unit/SigninRequest.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ describe("SigninRequest", function() {
175175
subject.url.should.contain("resource=foo");
176176
});
177177

178+
it("should include response_mode", function() {
179+
settings.response_mode = "foo";
180+
subject = new SigninRequest(settings);
181+
subject.url.should.contain("response_mode=foo");
182+
});
183+
178184
it("should include request", function() {
179185
settings.request = "foo";
180186
subject = new SigninRequest(settings);
@@ -201,7 +207,6 @@ describe("SigninRequest", function() {
201207
subject = new SigninRequest(settings);
202208
subject.url.should.contain("code_challenge=");
203209
subject.url.should.contain("code_challenge_method=S256");
204-
subject.url.should.contain("response_mode=fragment");
205210
});
206211

207212
it("should include hybrid flow params", function() {
@@ -210,7 +215,6 @@ describe("SigninRequest", function() {
210215
subject.url.should.contain("nonce=");
211216
subject.url.should.contain("code_challenge=");
212217
subject.url.should.contain("code_challenge_method=S256");
213-
subject.url.should.contain("response_mode=fragment");
214218
});
215219
});
216220

0 commit comments

Comments
 (0)