diff --git a/src/MetadataService.js b/src/MetadataService.js index e5c8fad1..d6d2b97b 100644 --- a/src/MetadataService.js +++ b/src/MetadataService.js @@ -58,7 +58,11 @@ export class MetadataService { return this._jsonService.getJson(this.metadataUrl) .then(metadata => { Log.debug("MetadataService.getMetadata: json received"); - this._settings.metadata = metadata; + + var mergedMetadata = this._settings.metadataSeed || {}; + Object.assign(mergedMetadata, metadata); + + this._settings.metadata = mergedMetadata; return metadata; }); } diff --git a/src/OidcClientSettings.js b/src/OidcClientSettings.js index 1b381b39..530d4c9e 100644 --- a/src/OidcClientSettings.js +++ b/src/OidcClientSettings.js @@ -18,7 +18,7 @@ const DefaultClockSkewInSeconds = 60 * 5; export class OidcClientSettings { constructor({ // metadata related - authority, metadataUrl, metadata, signingKeys, + authority, metadataUrl, metadata, signingKeys, metadataSeed, // client related client_id, client_secret, response_type = DefaultResponseType, scope = DefaultScope, redirect_uri, post_logout_redirect_uri, @@ -44,6 +44,7 @@ export class OidcClientSettings { this._authority = authority; this._metadataUrl = metadataUrl; this._metadata = metadata; + this._metadataSeed = metadataSeed; this._signingKeys = signingKeys; this._client_id = client_id; @@ -172,6 +173,12 @@ export class OidcClientSettings { set metadata(value) { this._metadata = value; } + get metadataSeed() { + return this._metadataSeed; + } + set metadataSeed(value) { + this._metadataSeed = value; + } get signingKeys() { return this._signingKeys; diff --git a/test/unit/MetadataService.spec.js b/test/unit/MetadataService.spec.js index 561c4d0a..ac597094 100644 --- a/test/unit/MetadataService.spec.js +++ b/test/unit/MetadataService.spec.js @@ -105,12 +105,25 @@ describe("MetadataService", function() { it("should cache metadata from json call", function(done) { settings.metadataUrl = "http://sts/metadata"; - stubJsonService.result = Promise.resolve("test"); + stubJsonService.result = Promise.resolve({test:"value"}); + + let p = subject.getMetadata(); + + p.then(result => { + settings.metadata.should.deep.equal({test:"value"}); + done(); + }); + }); + + it("should merge metadata from seed", function(done) { + settings.metadataUrl = "http://sts/metadata"; + settings.metadataSeed = {test1:"one"}; + stubJsonService.result = Promise.resolve({test2:"two"}); let p = subject.getMetadata(); p.then(result => { - settings.metadata.should.equal("test"); + settings.metadata.should.deep.equal({test1:"one", test2:"two"}); done(); }); });