From 0c8a8f242effe2e444db36271de68b4b71ea8489 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 10 Jul 2018 21:03:15 +0200 Subject: [PATCH] improvement(discovery): allow custom discovery location --- lib/issuer.js | 2 +- test/issuer/discover_issuer.test.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/issuer.js b/lib/issuer.js index 076dcd18..540e0775 100644 --- a/lib/issuer.js +++ b/lib/issuer.js @@ -176,7 +176,7 @@ class Issuer { static discover(uri) { const parsed = url.parse(uri); - if (parsed.pathname.endsWith(OIDC_DISCOVERY) || parsed.pathname.startsWith(OAUTH2_DISCOVERY)) { + if (parsed.pathname.includes('/.well-known/')) { return this.httpClient.get(uri, this.httpOptions()) .then(expectResponseWithBody(200)) .then(response => new this(JSON.parse(response.body))) diff --git a/test/issuer/discover_issuer.test.js b/test/issuer/discover_issuer.test.js index 6981cbad..e8b7589d 100644 --- a/test/issuer/discover_issuer.test.js +++ b/test/issuer/discover_issuer.test.js @@ -14,6 +14,28 @@ const fail = () => { throw new Error('expected promise to be rejected'); }; afterEach(nock.cleanAll); + describe('custom /.well-known', function () { + it('accepts and assigns the discovered metadata', function () { + nock('https://op.example.com', { allowUnmocked: true }) + .get('/.well-known/example-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/example-configuration').then(function (issuer) { + expect(issuer).to.have.property('authorization_endpoint', 'https://op.example.com/o/oauth2/v2/auth'); + expect(issuer).to.have.property('issuer', 'https://op.example.com'); + expect(issuer).to.have.property('jwks_uri', 'https://op.example.com/oauth2/v3/certs'); + expect(issuer).to.have.property('token_endpoint', 'https://op.example.com/oauth2/v4/token'); + expect(issuer).to.have.property('userinfo_endpoint', 'https://op.example.com/oauth2/v3/userinfo'); + }); + }); + }); + describe('/.well-known/openid-configuration', function () { it('accepts and assigns the discovered metadata', function () { nock('https://op.example.com', { allowUnmocked: true })