Skip to content

Commit

Permalink
Revert "feat: merge openid-configuration and metdata"
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen authored Feb 13, 2021
1 parent e7093cf commit 18c9128
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 47 deletions.
24 changes: 4 additions & 20 deletions src/MetadataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class MetadataService {

this._settings = settings;
this._jsonService = new JsonServiceCtor(['application/jwk-set+json']);
this._metadata_promise;
}

get metadataUrl() {
Expand Down Expand Up @@ -44,39 +43,24 @@ export class MetadataService {
}

getMetadata() {
// metadata was preloaded and no url was provided, so use the supplied data.
if (!this.metadataUrl && this._settings.metadata) {
if (this._settings.metadata) {
Log.debug("MetadataService.getMetadata: Returning metadata from settings");
return Promise.resolve(this._settings.metadata);
}

// no url was provided and settings were not pre-loaded then throw an error.
if (!this.metadataUrl) {
Log.error("MetadataService.getMetadata: No authority or metadataUrl configured on settings");
return Promise.reject(new Error("No authority or metadataUrl configured on settings"));
}

// if we've already started fetching metadata return the existing promise so we don't call it again.
if (this._metadata_promise) {
Log.debug("MetadataService.getMetadata: getting metadata from cache promise", this.metadataUrl);
return this._metadata_promise
}

Log.debug("MetadataService.getMetadata: getting metadata from", this.metadataUrl);

this._metadata_promise = this._jsonService.getJson(this.metadataUrl)
return this._jsonService.getJson(this.metadataUrl)
.then(metadata => {
Log.debug("MetadataService.getMetadata: json received");
// overlay .well-known/openid-configuration over seeded setting. this allows consumers to set values
// like end_session_url for Auth0 when it is not available in the configuration endpoint.
// precedence was set on the assumption the issuers hosted configuration is always more accurate
// than what the developer seeded the client with.
if (!this._settings.metadata) this._settings.metadata = {}
Object.assign(this._settings.metadata, metadata);
return this._settings.metadata;
this._settings.metadata = metadata;
return metadata;
});

return this._metadata_promise;
}

getIssuer() {
Expand Down
31 changes: 4 additions & 27 deletions test/unit/MetadataService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,24 @@ describe("MetadataService", function() {

it("should return metadata from json call", function(done) {
settings.metadataUrl = "http://sts/metadata";
const expected = { test: "test" };
stubJsonService.result = Promise.resolve(expected);
stubJsonService.result = Promise.resolve("test");

let p = subject.getMetadata();

p.then(result => {
result.should.deep.equal(expected);
result.should.equal("test");
done();
});
});

it("should cache metadata from json call", function(done) {
settings.metadataUrl = "http://sts/metadata";
const expected = { test: "test" };
stubJsonService.result = Promise.resolve(expected);
stubJsonService.result = Promise.resolve("test");

let p = subject.getMetadata();

p.then(result => {
settings.metadata.should.deep.equal(expected);
settings.metadata.should.equal("test");
done();
});
});
Expand All @@ -129,27 +127,6 @@ describe("MetadataService", function() {
});
});

it("should return merge openid-configuration from json call and injected metadata", function(done) {
settings.metadataUrl = "http://sts/metadata";
settings.metadata = {
property1: "injected",
property2: "injected"
}
const response = { property2: "merged" };
const expected = {
property1: "injected",
property2: "merged"
}
stubJsonService.result = Promise.resolve(response);

let p = subject.getMetadata();

p.then(result => {
result.should.deep.equal(expected);
done();
});
});

});

describe("_getMetadataProperty", function() {
Expand Down

0 comments on commit 18c9128

Please sign in to comment.