Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: issuer discovery #637

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions lib/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,8 @@ class Issuer {
}

static async discover(uri) {
const parsed = url.parse(uri);

if (parsed.pathname.includes('/.well-known/')) {
const response = await request.call(this, {
method: 'GET',
responseType: 'json',
url: uri,
headers: {
Accept: 'application/json',
},
});
const body = processResponse(response);
return new Issuer({
...ISSUER_DEFAULTS,
...body,
[AAD_MULTITENANT]: !!AAD_MULTITENANT_DISCOVERY.find((discoveryURL) =>
uri.startsWith(discoveryURL),
),
});
}

let pathname;
if (parsed.pathname.endsWith('/')) {
pathname = `${parsed.pathname}.well-known/openid-configuration`;
} else {
pathname = `${parsed.pathname}/.well-known/openid-configuration`;
}

const wellKnownUri = url.format({ ...parsed, pathname });
const wellKnownUri = getUri(uri);
big-kahuna-burger marked this conversation as resolved.
Show resolved Hide resolved

const response = await request.call(this, {
method: 'GET',
Expand All @@ -184,6 +157,21 @@ class Issuer {
wellKnownUri.startsWith(discoveryURL),
),
});

function getUri(uri) {
const parsed = url.parse(uri);
if (parsed.pathname.includes('/.well-known/')) {
return uri;
} else {
let pathname;
if (parsed.pathname.endsWith('/')) {
pathname = `${parsed.pathname}.well-known/openid-configuration`;
} else {
pathname = `${parsed.pathname}/.well-known/openid-configuration`;
}
return url.format({ ...parsed, pathname });
}
}
}

async reloadJwksUri() {
Expand Down