Skip to content

Commit

Permalink
add metadataSeed to allow merging discovery document into additional …
Browse files Browse the repository at this point in the history
…metadata
  • Loading branch information
brockallen committed Feb 13, 2021
1 parent 18c9128 commit 2280f3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/MetadataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/OidcClientSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions test/unit/MetadataService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 2280f3d

Please sign in to comment.