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

[SDK-3887] Always honor auth0Logout config #447

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ async function get(config) {
applyHttpOptionsCustom(client);
client[custom.clock_tolerance] = config.clockTolerance;

if (config.idpLogout && !issuer.end_session_endpoint) {
if (config.idpLogout) {
if (
config.auth0Logout ||
url.parse(issuer.issuer).hostname.match('\\.auth0\\.com$')
(url.parse(issuer.issuer).hostname.match('\\.auth0\\.com$') &&
config.auth0Logout !== false)
) {
Object.defineProperty(client, 'endSessionUrl', {
value(params) {
Expand All @@ -130,7 +131,7 @@ async function get(config) {
return url.format(parsedUrl);
},
});
} else {
} else if (!issuer.end_session_endpoint) {
debug('the issuer does not support RP-Initiated Logout');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const paramsSchema = Joi.object({
})
.default()
.unknown(false),
auth0Logout: Joi.boolean().optional().default(false),
auth0Logout: Joi.boolean().optional(),
tokenEndpointParams: Joi.object().optional(),
authorizationParams: Joi.object({
response_type: Joi.string()
Expand Down
89 changes: 89 additions & 0 deletions test/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,95 @@ describe('client initialization', function () {
});
});

describe('auth0 logout option and discovery', function () {
const base = {
secret: '__test_session_secret__',
clientID: '__test_client_id__',
clientSecret: '__test_client_secret__',
issuerBaseURL: 'https://op.example.com',
baseURL: 'https://example.org',
idpLogout: true,
};

it('should use discovered logout endpoint by default', async function () {
const client = await getClient(getConfig(base));
assert.equal(client.endSessionUrl({}), wellKnown.end_session_endpoint);
});

it('should use auth0 logout endpoint if configured', async function () {
const client = await getClient(getConfig({ ...base, auth0Logout: true }));
assert.equal(
client.endSessionUrl({}),
'https://op.example.com/v2/logout?client_id=__test_client_id__'
);
});

it('should use auth0 logout endpoint if domain is auth0.com', async function () {
nock('https://foo.auth0.com')
.get('/.well-known/openid-configuration')
.reply(200, { ...wellKnown, issuer: 'https://foo.auth0.com/' });
const client = await getClient(
getConfig({ ...base, issuerBaseURL: 'https://foo.auth0.com' })
);
assert.equal(
client.endSessionUrl({}),
'https://foo.auth0.com/v2/logout?client_id=__test_client_id__'
);
});

it('should use auth0 logout endpoint if domain is auth0.com and configured', async function () {
nock('https://foo.auth0.com')
.get('/.well-known/openid-configuration')
.reply(200, { ...wellKnown, issuer: 'https://foo.auth0.com/' });
const client = await getClient(
getConfig({
...base,
issuerBaseURL: 'https://foo.auth0.com',
auth0Logout: true,
})
);
assert.equal(
client.endSessionUrl({}),
'https://foo.auth0.com/v2/logout?client_id=__test_client_id__'
);
});

it('should not use discovered logout endpoint if domain is auth0.com but configured with auth0logout false', async function () {
nock('https://foo.auth0.com')
.get('/.well-known/openid-configuration')
.reply(200, {
...wellKnown,
issuer: 'https://foo.auth0.com/',
end_session_endpoint: 'https://foo.auth0.com/oidc/logout',
});
const client = await getClient(
getConfig({
...base,
issuerBaseURL: 'https://foo.auth0.com',
auth0Logout: false,
})
);
assert.equal(
client.endSessionUrl({}),
'https://foo.auth0.com/oidc/logout'
);
});

it('should create client with no end_session_endpoint', async function () {
nock('https://op2.example.com')
.get('/.well-known/openid-configuration')
.reply(200, {
...wellKnown,
issuer: 'https://op2.example.com',
end_session_endpoint: undefined,
});
const client = await getClient(
getConfig({ ...base, issuerBaseURL: 'https://op2.example.com' })
);
assert.throws(() => client.endSessionUrl({}));
});
});

describe('client respects httpTimeout configuration', function () {
const config = getConfig({
secret: '__test_session_secret__',
Expand Down
6 changes: 3 additions & 3 deletions test/config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ describe('get config', () => {
});
});

it('auth0Logout and idpLogout should default to false', () => {
it('auth0Logout should default to undefined and idpLogout should default to false', () => {
const config = getConfig(defaultConfig);
assert.include(config, {
auth0Logout: false,
idpLogout: false,
});
assert.isUndefined(config.auth0Logout);
});

it('should not set auth0Logout to true when idpLogout is true', () => {
Expand All @@ -100,9 +100,9 @@ describe('get config', () => {
idpLogout: true,
});
assert.include(config, {
auth0Logout: false,
idpLogout: true,
});
assert.isUndefined(config.auth0Logout);
});

it('should set default route paths', () => {
Expand Down