Skip to content

Commit 47d7698

Browse files
committed
optionsl oidc request params
1 parent 0a81075 commit 47d7698

6 files changed

Lines changed: 172 additions & 61 deletions

File tree

‎src/OidcClientService.js‎

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import SigninRequest from './SigninRequest';
55
import SignoutRequest from './SignoutRequest';
66
import WebStorageStateStore from './WebStorageStateStore';
77

8-
// const OidcOptionalParams = ["prompt", "display", "max_age", "ui_locales", "id_token_hint", "login_hint", "acr_values"];
9-
108
export default class OidcClientService {
119
constructor(settings,
1210
stateStore = new WebStorageStateStore(),
@@ -26,13 +24,23 @@ export default class OidcClientService {
2624
return this._settings;
2725
}
2826

29-
createSigninRequest({response_type, scope, redirect_uri, data}={}) {
27+
createSigninRequest({
28+
response_type, scope, redirect_uri, data,
29+
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values}={}
30+
) {
3031
Log.info("OidcClientService.createSigninRequest");
3132

3233
let client_id = this._settings.client_id;
3334
response_type = response_type || this._settings.response_type;
3435
scope = scope || this._settings.scope;
3536
redirect_uri = redirect_uri || this._settings.redirect_uri;
37+
38+
// id_token_hint, login_hint aren't allowed on _settings
39+
prompt = prompt || this._settings.prompt;
40+
display = display || this._settings.display;
41+
max_age = max_age || this._settings.max_age ;
42+
ui_locales = ui_locales || this._settings.ui_locales;
43+
acr_values = acr_values || this._settings.acr_values;
3644

3745
return this._metadataService.getAuthorizationEndpoint().then(url => {
3846
Log.info("Received authorization endpoint", url);
@@ -42,15 +50,16 @@ export default class OidcClientService {
4250
redirect_uri,
4351
response_type,
4452
scope,
45-
data
53+
data,
54+
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values
4655
});
4756
}, err => {
4857
Log.error("Failed to create signin request", err);
4958
throw new Error("Failed to create signin request");
5059
});
5160
}
5261

53-
processSigninResponse(stateString){
62+
processSigninResponse(url){
5463
Log.info("OidcClientService.processSigninResponse");
5564
}
5665

@@ -73,62 +82,9 @@ export default class OidcClientService {
7382
});
7483
}
7584

76-
processSignoutResponse(stateString){
85+
processSignoutResponse(url){
7786
Log.info("OidcClientService.processSignoutResponse");
7887
}
79-
80-
// OidcClient.prototype.createTokenRequestAsync = function () {
81-
// log("OidcClient.createTokenRequestAsync");
82-
83-
// var client = this;
84-
// var settings = client._settings;
85-
86-
// return client.loadAuthorizationEndpoint().then(function (authorization_endpoint) {
87-
88-
// var state = rand();
89-
// var url = authorization_endpoint + "?state=" + encodeURIComponent(state);
90-
91-
// if (client.isOidc) {
92-
// var nonce = rand();
93-
// url += "&nonce=" + encodeURIComponent(nonce);
94-
// }
95-
96-
// var required = ["client_id", "redirect_uri", "response_type", "scope"];
97-
// required.forEach(function (key) {
98-
// var value = settings[key];
99-
// if (value) {
100-
// url += "&" + key + "=" + encodeURIComponent(value);
101-
// }
102-
// });
103-
104-
// var optional = ["prompt", "display", "max_age", "ui_locales", "id_token_hint", "login_hint", "acr_values"];
105-
// optional.forEach(function (key) {
106-
// var value = settings[key];
107-
// if (value) {
108-
// url += "&" + key + "=" + encodeURIComponent(value);
109-
// }
110-
// });
111-
112-
// var request_state = {
113-
// oidc: client.isOidc,
114-
// oauth: client.isOAuth,
115-
// state: state
116-
// };
117-
118-
// if (nonce) {
119-
// request_state["nonce"] = nonce;
120-
// }
121-
122-
// settings.request_state_store.setItem(settings.request_state_key, JSON.stringify(request_state));
123-
124-
// return {
125-
// request_state: request_state,
126-
// url: url
127-
// };
128-
// });
129-
// }
130-
131-
13288

13389
// OidcClient.prototype.processResponseAsync = function (queryString) {
13490
// log("OidcClient.processResponseAsync");

‎src/OidcClientSettings.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default class OidcClientSettings {
1111
// client related
1212
client_id, response_type = DefaultResponseType, scope = DefaultScope,
1313
redirect_uri, post_logout_redirect_uri,
14+
// optional protocol
15+
prompt, display, max_age, ui_locales, acr_values,
1416
// behavior flags
1517
filterProtocolClaims = true
1618
}) {
@@ -29,6 +31,12 @@ export default class OidcClientSettings {
2931
this._scope = scope;
3032
this._redirect_uri = redirect_uri;
3133
this._post_logout_redirect_uri = post_logout_redirect_uri;
34+
35+
this._prompt = prompt;
36+
this._display = display;
37+
this._max_age = max_age;
38+
this._ui_locales = ui_locales;
39+
this._acr_values = acr_values;
3240

3341
this._filterProtocolClaims = !!filterProtocolClaims;
3442
}
@@ -51,6 +59,23 @@ export default class OidcClientSettings {
5159
return this._post_logout_redirect_uri;
5260
}
5361

62+
// optional protocol params
63+
get prompt(){
64+
return this._prompt;
65+
}
66+
get display(){
67+
return this._display;
68+
}
69+
get max_age(){
70+
return this._max_age;
71+
}
72+
get ui_locales(){
73+
return this._ui_locales;
74+
}
75+
get acr_values(){
76+
return this._acr_values;
77+
}
78+
5479
// metadata
5580
get authority() {
5681
return this._authority;

‎src/SigninRequest.js‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import Log from './Log';
22
import UrlUtility from './UrlUtility';
33
import State from './State';
44

5+
const OidcOptionalRequestParams = ["prompt", "display", "max_age", "ui_locales", "id_token_hint", "login_hint", "acr_values"];
6+
57
export default class SigninRequest {
6-
constructor({url, client_id, redirect_uri, response_type, scope, data}) {
8+
constructor({
9+
url, client_id, redirect_uri, response_type, scope, data,
10+
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values
11+
}) {
712

813
if (!url){
914
Log.error("No url passed to SigninRequest");
@@ -32,6 +37,15 @@ export default class SigninRequest {
3237
this._response_type = response_type;
3338
this._scope = scope;
3439
this._state = new State({nonce:this.isOidc, data});
40+
41+
// optional
42+
this._prompt = prompt;
43+
this._display = display;
44+
this._max_age = max_age;
45+
this._ui_locales = ui_locales;
46+
this._id_token_hint = id_token_hint;
47+
this._login_hint = login_hint;
48+
this._acr_values = acr_values;
3549
}
3650

3751
get state(){
@@ -41,14 +55,22 @@ export default class SigninRequest {
4155
get signinUrl(){
4256
if (!this._signinUrl){
4357
this._signinUrl = this._url;
58+
4459
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "client_id", this._client_id);
4560
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "redirect_uri", this._redirect_uri);
4661
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "response_type", this._response_type);
4762
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "scope", this._scope);
4863
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "state", this._state.id);
64+
4965
if (this.isOidc){
5066
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, "nonce", this._state.nonce);
5167
}
68+
69+
OidcOptionalRequestParams.forEach(key => {
70+
if (this["_" + key]){
71+
this._signinUrl = UrlUtility.addQueryParam(this._signinUrl, key, this["_" + key]);
72+
}
73+
});
5274
}
5375

5476
return this._signinUrl;

‎test/OidcClientService.spec.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,33 @@ describe("OidcClientService", function() {
7070
data: 'foo',
7171
response_type: 'bar',
7272
scope: 'baz',
73-
redirect_uri: 'quux'
73+
redirect_uri: 'quux',
74+
prompt:'p',
75+
display:'d',
76+
max_age:'m',
77+
ui_locales:'u',
78+
id_token_hint:'ith',
79+
login_hint:'lh',
80+
acr_values:'av'
7481
});
7582

7683
p.then(request => {
7784
request.state.data.should.equal('foo');
7885

7986
var url = request.signinUrl;
87+
console.log(url);
8088
url.should.contain("http://sts/authorize");
8189
url.should.contain("response_type=bar");
8290
url.should.contain("scope=baz");
8391
url.should.contain("redirect_uri=quux");
92+
url.should.contain("prompt=p");
93+
url.should.contain("display=d");
94+
url.should.contain("max_age=m");
95+
url.should.contain("ui_locales=u");
96+
url.should.contain("id_token_hint=ith");
97+
url.should.contain("login_hint=lh");
98+
url.should.contain("acr_values=av");
99+
84100
done();
85101
});
86102
});

‎test/OidcClientSettings.spec.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,56 @@ describe("OidcClientSettings", function() {
9393
});
9494
});
9595

96+
describe("prompt", function() {
97+
it("should return value from initial settings", function() {
98+
let subject = new OidcClientSettings({
99+
client_id: 'client',
100+
prompt: "foo"
101+
});
102+
subject.prompt.should.equal("foo");
103+
});
104+
});
105+
106+
describe("display", function() {
107+
it("should return value from initial settings", function() {
108+
let subject = new OidcClientSettings({
109+
client_id: 'client',
110+
display: "foo"
111+
});
112+
subject.display.should.equal("foo");
113+
});
114+
});
115+
116+
describe("max_age", function() {
117+
it("should return value from initial settings", function() {
118+
let subject = new OidcClientSettings({
119+
client_id: 'client',
120+
max_age: "foo"
121+
});
122+
subject.max_age.should.equal("foo");
123+
});
124+
});
125+
126+
describe("ui_locales", function() {
127+
it("should return value from initial settings", function() {
128+
let subject = new OidcClientSettings({
129+
client_id: 'client',
130+
ui_locales: "foo"
131+
});
132+
subject.ui_locales.should.equal("foo");
133+
});
134+
});
135+
136+
describe("acr_values", function() {
137+
it("should return value from initial settings", function() {
138+
let subject = new OidcClientSettings({
139+
client_id: 'client',
140+
acr_values: "foo"
141+
});
142+
subject.acr_values.should.equal("foo");
143+
});
144+
});
145+
96146
describe("authority", function() {
97147
it("should return value from initial settings", function() {
98148
let subject = new OidcClientSettings({

‎test/SigninRequest.spec.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,48 @@ describe("SigninRequest", function() {
110110
it("should include state", function() {
111111
subject.signinUrl.should.contain("state=" + subject.state.id);
112112
});
113+
114+
it("should include prompt", function() {
115+
settings.prompt = "foo";
116+
subject = new SigninRequest(settings);
117+
subject.signinUrl.should.contain("prompt=foo");
118+
});
119+
120+
it("should include display", function() {
121+
settings.display = "foo";
122+
subject = new SigninRequest(settings);
123+
subject.signinUrl.should.contain("display=foo");
124+
});
125+
126+
it("should include max_age", function() {
127+
settings.max_age = "foo";
128+
subject = new SigninRequest(settings);
129+
subject.signinUrl.should.contain("max_age=foo");
130+
});
131+
132+
it("should include ui_locales", function() {
133+
settings.ui_locales = "foo";
134+
subject = new SigninRequest(settings);
135+
subject.signinUrl.should.contain("ui_locales=foo");
136+
});
137+
138+
it("should include id_token_hint", function() {
139+
settings.id_token_hint = "foo";
140+
subject = new SigninRequest(settings);
141+
subject.signinUrl.should.contain("id_token_hint=foo");
142+
});
143+
144+
it("should include login_hint", function() {
145+
settings.login_hint = "foo";
146+
subject = new SigninRequest(settings);
147+
subject.signinUrl.should.contain("login_hint=foo");
148+
});
149+
150+
it("should include acr_values", function() {
151+
settings.acr_values = "foo";
152+
subject = new SigninRequest(settings);
153+
subject.signinUrl.should.contain("acr_values=foo");
154+
});
113155

114156
});
115157

0 commit comments

Comments
 (0)