Skip to content

Commit

Permalink
Merge pull request IdentityModel#980 from volkc-basf/dev
Browse files Browse the repository at this point in the history
Please allow extraTokenParams to be configured via OidcClient settings
  • Loading branch information
brockallen authored Dec 16, 2019
2 parents dd68dc5 + 763992f commit 96c45ba
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/OidcClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class OidcClient {
resource = resource || this._settings.resource;
response_mode = response_mode || this._settings.response_mode;
extraQueryParams = extraQueryParams || this._settings.extraQueryParams;
extraTokenParams = extraTokenParams || this._settings.extraTokenParams;

let authority = this._settings.authority;

Expand Down
16 changes: 15 additions & 1 deletion src/OidcClientSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class OidcClientSettings {
ResponseValidatorCtor = ResponseValidator,
MetadataServiceCtor = MetadataService,
// extra query params
extraQueryParams = {}
extraQueryParams = {},
extraTokenParams = {}
} = {}) {

this._authority = authority;
Expand Down Expand Up @@ -65,6 +66,7 @@ export class OidcClientSettings {
this._metadataService = new MetadataServiceCtor(this);

this._extraQueryParams = typeof extraQueryParams === 'object' ? extraQueryParams : {};
this._extraTokenParams = typeof extraTokenParams === 'object' ? extraTokenParams : {};
}

// client config
Expand Down Expand Up @@ -204,4 +206,16 @@ export class OidcClientSettings {
this._extraQueryParams = {};
}
}

// extra token params
get extraTokenParams() {
return this._extraTokenParams;
}
set extraTokenParams(value) {
if (typeof value === 'object'){
this._extraTokenParams = value;
} else {
this._extraTokenParams = {};
}
}
}
47 changes: 47 additions & 0 deletions test/unit/OidcClientSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,4 +459,51 @@ describe("OidcClientSettings", function () {
});
})

describe("extraTokenParams", function() {

it("should use default value", function () {
let subject = new OidcClientSettings({
client_id: 'client'
});
subject.extraTokenParams.should.deep.equal({});
});

it("should return value from initial settings", function () {
let subject = new OidcClientSettings({
client_id: 'client',
extraTokenParams: {
'resourceServer': 'abc'
}
});
subject.extraTokenParams.should.deep.equal({ 'resourceServer': 'abc' });
});

it("should not set value from initial settings if not object, but set default value ({})", function () {
let subject = new OidcClientSettings({
client_id: 'client',
extraTokenParams: 123456
});
subject.extraTokenParams.should.deep.equal({});
});

it("should set it if object", function () {
let subject = new OidcClientSettings({
client_id: 'client',
});
subject.extraTokenParams = { 'resourceServer': 'abc' };
subject.extraTokenParams.should.deep.equal({ 'resourceServer': 'abc' });
});

it("should clear it if not object", function() {
let subject = new OidcClientSettings({
client_id: 'client',
extraTokenParams: {
'resourceServer': 'abc',
}
});
subject.extraTokenParams = undefined;
subject.extraTokenParams.should.deep.equal({});
});
})

});
10 changes: 10 additions & 0 deletions test/unit/SigninRequest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ describe("SigninRequest", function() {
subject.url.should.contain('hd=domain.com&foo=bar');
});

it("should store extra token params in state", function() {
settings.extraTokenParams = {
'resourceServer': 'abc',
};
subject = new SigninRequest(settings);
assert.deepEqual(subject.state.extraTokenParams, {
'resourceServer': 'abc'
});
});

it("should include code flow params", function() {
settings.response_type = "code";
subject = new SigninRequest(settings);
Expand Down
5 changes: 5 additions & 0 deletions test/unit/SigninState.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ describe("SigninState", function() {
var subject = new SigninState({ request_type: 'xoxo' });
subject.request_type.should.be.equal('xoxo');
});

it("should accept extraTokenParams", function() {
var subject = new SigninState({ extraTokenParams: { 'resourceServer' : 'abc' } });
assert.deepEqual(subject.extraTokenParams, { 'resourceServer' : 'abc' });
});
});

it("can serialize and then deserialize", function() {
Expand Down

0 comments on commit 96c45ba

Please sign in to comment.