diff --git a/src/OidcClient.js b/src/OidcClient.js index b5b69fa0..bc22b799 100644 --- a/src/OidcClient.js +++ b/src/OidcClient.js @@ -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; diff --git a/src/OidcClientSettings.js b/src/OidcClientSettings.js index 1fdba17c..de6ded54 100644 --- a/src/OidcClientSettings.js +++ b/src/OidcClientSettings.js @@ -31,7 +31,8 @@ export class OidcClientSettings { ResponseValidatorCtor = ResponseValidator, MetadataServiceCtor = MetadataService, // extra query params - extraQueryParams = {} + extraQueryParams = {}, + extraTokenParams = {} } = {}) { this._authority = authority; @@ -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 @@ -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 = {}; + } + } } diff --git a/test/unit/OidcClientSettings.spec.js b/test/unit/OidcClientSettings.spec.js index f6ffe351..1d9cd6d2 100644 --- a/test/unit/OidcClientSettings.spec.js +++ b/test/unit/OidcClientSettings.spec.js @@ -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({}); + }); + }) + }); diff --git a/test/unit/SigninRequest.spec.js b/test/unit/SigninRequest.spec.js index ca4fa125..103d42b7 100644 --- a/test/unit/SigninRequest.spec.js +++ b/test/unit/SigninRequest.spec.js @@ -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); diff --git a/test/unit/SigninState.spec.js b/test/unit/SigninState.spec.js index 8486cdbf..ed2583bf 100644 --- a/test/unit/SigninState.spec.js +++ b/test/unit/SigninState.spec.js @@ -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() {