From 74b593e13069a1cd9d190224c5d86dd4a462613b Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 9 Oct 2018 22:45:34 -0300 Subject: [PATCH] fix: assign Discovery 1.0 defaults when discovering with .well-known --- lib/issuer.js | 2 +- test/issuer/discover_issuer.test.js | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/issuer.js b/lib/issuer.js index 1e8f395d..1a7d27a7 100644 --- a/lib/issuer.js +++ b/lib/issuer.js @@ -196,7 +196,7 @@ class Issuer { if (parsed.pathname.includes('/.well-known/')) { return this.httpClient.get(uri, this.httpOptions()) .then(expectResponseWithBody(200)) - .then(response => new this(JSON.parse(response.body))) + .then(response => new this(Object.assign({}, ISSUER_DEFAULTS, JSON.parse(response.body)))) .catch(errorHandler.bind(this)); } diff --git a/test/issuer/discover_issuer.test.js b/test/issuer/discover_issuer.test.js index c8d4c501..5d784cb3 100644 --- a/test/issuer/discover_issuer.test.js +++ b/test/issuer/discover_issuer.test.js @@ -166,7 +166,31 @@ const fail = () => { throw new Error('expected promise to be rejected'); }; }); }); - it('assigns Discovery 1.0 defaults', function () { + it('assigns Discovery 1.0 defaults 1/2', function () { + nock('https://op.example.com', { allowUnmocked: true }) + .get('/.well-known/openid-configuration') + .reply(200, { + authorization_endpoint: 'https://op.example.com/o/oauth2/v2/auth', + issuer: 'https://op.example.com', + jwks_uri: 'https://op.example.com/oauth2/v3/certs', + token_endpoint: 'https://op.example.com/oauth2/v4/token', + userinfo_endpoint: 'https://op.example.com/oauth2/v3/userinfo', + }); + + return Issuer.discover('https://op.example.com/.well-known/openid-configuration') + .then((issuer) => { + expect(issuer).to.have.property('claims_parameter_supported', false); + expect(issuer).to.have.property('grant_types_supported').to.eql(['authorization_code', 'implicit']); + expect(issuer).to.have.property('request_parameter_supported', false); + expect(issuer).to.have.property('request_uri_parameter_supported', true); + expect(issuer).to.have.property('require_request_uri_registration', false); + expect(issuer).to.have.property('response_modes_supported').to.eql(['query', 'fragment']); + expect(issuer).to.have.property('claim_types_supported').to.eql(['normal']); + expect(issuer).to.have.property('token_endpoint_auth_methods_supported').to.eql(['client_secret_basic']); + }); + }); + + it('assigns Discovery 1.0 defaults 2/2', function () { nock('https://op.example.com', { allowUnmocked: true }) .get('/.well-known/openid-configuration') .reply(200, {