Skip to content

Commit 63397c8

Browse files
committed
allow for optional metadata properties
1 parent 7d0425d commit 63397c8

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

src/MetadataService.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,30 @@ export default class MetadataService {
5555

5656
getCheckSessionIframe() {
5757
Log.info("MetadataService.getCheckSessionIframe");
58-
return this._getMetadataProperty("check_session_iframe");
58+
return this._getMetadataProperty("check_session_iframe", true);
5959
}
6060

6161
getEndSessionEndpoint() {
6262
Log.info("MetadataService.getEndSessionEndpoint");
63-
return this._getMetadataProperty("end_session_endpoint");
63+
return this._getMetadataProperty("end_session_endpoint", true);
6464
}
6565

66-
_getMetadataProperty(name) {
66+
_getMetadataProperty(name, optional=false) {
6767
Log.info("MetadataService._getMetadataProperty", name);
6868

6969
return this.getMetadata().then(metadata => {
7070
Log.info("metadata recieved");
7171

7272
if (metadata[name] === undefined) {
73-
Log.error("Metadata does not contain property " + name);
74-
throw new Error("Metadata does not contain property " + name);
73+
74+
if (optional === true) {
75+
Log.warn("Metadata does not contain optional property " + name);
76+
return undefined;
77+
}
78+
else {
79+
Log.error("Metadata does not contain property " + name);
80+
throw new Error("Metadata does not contain property " + name);
81+
}
7582
}
7683

7784
return metadata[name];

src/OidcClient.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ export default class OidcClient {
115115
post_logout_redirect_uri = post_logout_redirect_uri || this._settings.post_logout_redirect_uri;
116116

117117
return this._metadataService.getEndSessionEndpoint().then(url => {
118+
if (!url) {
119+
Log.error("No end session endpoint url returned");
120+
throw new Error("no end session endpoint");
121+
}
122+
118123
Log.info("Received end session endpoint", url);
119124

120125
let request = new SignoutRequest({

test/unit/MetadataService.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ describe("MetadataService", function() {
220220
});
221221
});
222222

223+
it("should support optional value", function(done) {
224+
settings.metadata = {
225+
};
226+
227+
let p = subject.getEndSessionEndpoint();
228+
229+
p.then(result => {
230+
assert.isUndefined(result);
231+
done();
232+
});
233+
});
234+
223235
});
224236

225237
describe("getCheckSessionIframe", function() {
@@ -237,6 +249,18 @@ describe("MetadataService", function() {
237249
});
238250
});
239251

252+
it("should support optional value", function(done) {
253+
settings.metadata = {
254+
};
255+
256+
let p = subject.getCheckSessionIframe();
257+
258+
p.then(result => {
259+
assert.isUndefined(result);
260+
done();
261+
});
262+
});
263+
240264
});
241265

242266
describe("getIssuer", function() {

test/unit/OidcClient.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ describe("OidcClient", function () {
272272
});
273273
});
274274

275+
it("should fail if no signout endpoint on metadata", function (done) {
276+
stubMetadataService.getEndSessionEndpointResult = Promise.resolve(undefined);
277+
278+
var p = subject.createSignoutRequest();
279+
280+
p.catch(err => {
281+
err.message.should.contain("no end session endpoint");
282+
done();
283+
});
284+
});
285+
275286
it("should store state", function (done) {
276287
stubMetadataService.getEndSessionEndpointResult = Promise.resolve("http://sts/signout");
277288

0 commit comments

Comments
 (0)