Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit400e7f8

Browse files
committed
added support for extra/custom query params with test
1 parentafbc66d commit400e7f8

File tree

5 files changed

+85
-6
lines changed

5 files changed

+85
-6
lines changed

‎src/OidcClient.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export default class OidcClient {
4040

4141
createSigninRequest({
4242
response_type, scope, redirect_uri,
43-
// data was meant to be the place a caller couldindiate the data to
43+
// data was meant to be the place a caller couldindicate the data to
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
46-
data, state,
47-
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,resource, request, request_uri}={},
46+
data, state, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
47+
resource, request, request_uri, extraQueryParams}={},
4848
stateStore
4949
){
5050
Log.debug("OidcClient.createSigninRequest");
@@ -61,6 +61,7 @@ export default 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+
extraQueryParams=extraQueryParams||this._settings.extraQueryParams;
6465

6566
letauthority=this._settings.authority;
6667

@@ -75,7 +76,8 @@ export default class OidcClient {
7576
scope,
7677
data:data||state,
7778
authority,
78-
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, request, request_uri
79+
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
80+
resource, request, request_uri, extraQueryParams,
7981
});
8082

8183
varsigninState=signinRequest.state;

‎src/OidcClientSettings.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export default class OidcClientSettings {
2828
// other behavior
2929
stateStore=newWebStorageStateStore(),
3030
ResponseValidatorCtor=ResponseValidator,
31-
MetadataServiceCtor=MetadataService
31+
MetadataServiceCtor=MetadataService,
32+
// extra query params
33+
extraQueryParams={}
3234
}={}){
3335

3436
this._authority=authority;
@@ -58,6 +60,8 @@ export default class OidcClientSettings {
5860
this._stateStore=stateStore;
5961
this._validator=newResponseValidatorCtor(this);
6062
this._metadataService=newMetadataServiceCtor(this);
63+
64+
this._extraQueryParams=typeofextraQueryParams==='object' ?extraQueryParams :{};
6165
}
6266

6367
// client config
@@ -179,4 +183,16 @@ export default class OidcClientSettings {
179183
getmetadataService(){
180184
returnthis._metadataService;
181185
}
186+
187+
// extra query params
188+
getextraQueryParams(){
189+
returnthis._extraQueryParams;
190+
}
191+
setextraQueryParams(value){
192+
if(typeofvalue==='object'){
193+
this._extraQueryParams=value;
194+
}else{
195+
this._extraQueryParams={};
196+
}
197+
}
182198
}

‎src/SigninRequest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default 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, request, request_uri
13+
data, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource,
14+
request, request_uri, extraQueryParams,
1415
}){
1516
if(!url){
1617
Log.error("No url passed to SigninRequest");
@@ -57,6 +58,10 @@ export default class SigninRequest {
5758
}
5859
}
5960

61+
for(letkeyinextraQueryParams){
62+
url=UrlUtility.addQueryParam(url,key,extraQueryParams[key])
63+
}
64+
6065
this.url=url;
6166
}
6267

‎test/unit/OidcClientSettings.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,51 @@ describe("OidcClientSettings", function () {
392392
});
393393
});
394394

395+
describe("extraQueryParams",function(){
396+
397+
it("should use default value",function(){
398+
letsubject=newOidcClientSettings({
399+
client_id:'client'
400+
});
401+
subject.extraQueryParams.should.deep.equal({});
402+
});
403+
404+
it("should return value from initial settings",function(){
405+
letsubject=newOidcClientSettings({
406+
client_id:'client',
407+
extraQueryParams:{
408+
'hd':'domain.com'
409+
}
410+
});
411+
subject.extraQueryParams.should.deep.equal({'hd':'domain.com'});
412+
});
413+
414+
it("should not set value from initial settings if not object, but set default value ({})",function(){
415+
letsubject=newOidcClientSettings({
416+
client_id:'client',
417+
extraQueryParams:123456
418+
});
419+
subject.extraQueryParams.should.deep.equal({});
420+
});
421+
422+
it("should set it if object",function(){
423+
letsubject=newOidcClientSettings({
424+
client_id:'client',
425+
});
426+
subject.extraQueryParams={'hd':'domain.com'};
427+
subject.extraQueryParams.should.deep.equal({'hd':'domain.com'});
428+
});
429+
430+
it("should clear it if not object",function(){
431+
letsubject=newOidcClientSettings({
432+
client_id:'client',
433+
extraQueryParams:{
434+
'hd':'domain.com',
435+
}
436+
});
437+
subject.extraQueryParams=undefined;
438+
subject.extraQueryParams.should.deep.equal({});
439+
});
440+
})
441+
395442
});

‎test/unit/SigninRequest.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ describe("SigninRequest", function() {
187187
subject.url.should.contain("request_uri=foo");
188188
});
189189

190+
it("should include extra query params",function(){
191+
settings.extraQueryParams={
192+
'hd':'domain.com',
193+
'foo':'bar'
194+
};
195+
subject=newSigninRequest(settings);
196+
subject.url.should.contain('hd=domain.com&foo=bar');
197+
});
198+
190199
});
191200

192201
describe("isOidc",function(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp