Skip to content

Commit

Permalink
improvement(discovery): allow custom discovery location
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jul 10, 2018
1 parent caaee59 commit 0c8a8f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/issuer.js
Expand Up @@ -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)))
Expand Down
22 changes: 22 additions & 0 deletions test/issuer/discover_issuer.test.js
Expand Up @@ -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 })
Expand Down

0 comments on commit 0c8a8f2

Please sign in to comment.