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

Honor params passed to logout over defaults #533

Merged
merged 1 commit into from
Nov 2, 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
4 changes: 2 additions & 2 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ class ResponseContext {

returnURL = client.endSessionUrl({
...config.logoutParams,
...params.logoutParams,
post_logout_redirect_uri: returnURL,
id_token_hint,
post_logout_redirect_uri: returnURL,
...params.logoutParams,
});
} catch (err) {
return next(err);
Expand Down
49 changes: 48 additions & 1 deletion test/logout.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('logout route', async () => {
assert.include(
response.headers,
{
location: `https://op.example.com/session/end?post_logout_redirect_uri=http%3A%2F%2Fexample.org&id_token_hint=${idToken}`,
location: `https://op.example.com/session/end?id_token_hint=${idToken}&post_logout_redirect_uri=http%3A%2F%2Fexample.org`,
},
'should redirect to the identity provider'
);
Expand Down Expand Up @@ -297,6 +297,53 @@ describe('logout route', async () => {
assert.equal(url.hostname, 'foo.com');
});

it('should honor logout url arguments over logout params', async () => {
const router = auth({
...defaultConfig,
idpLogout: true,
routes: { logout: false },
});
server = await createServer(router);
router.get('/logout', (req, res) =>
res.oidc.logout({
logoutParams: { post_logout_redirect_uri: 'https://bar.com' },
})
);

const { jar } = await login();
const {
response: {
headers: { location },
},
} = await logout(jar);
const url = new URL(
new URL(location).searchParams.get('post_logout_redirect_uri')
);
assert.equal(url.hostname, 'bar.com');
});

it('should honor logout id_token_hint arguments over default', async () => {
const router = auth({
...defaultConfig,
idpLogout: true,
routes: { logout: false },
});
server = await createServer(router);
router.get('/logout', (req, res) =>
res.oidc.logout({
logoutParams: { id_token_hint: null },
})
);

const { jar } = await login();
const {
response: {
headers: { location },
},
} = await logout(jar);
assert.notOk(new URL(location).searchParams.get('id_token_hint'));
});

it('should ignore undefined or null logout params', async () => {
server = await createServer(
auth({
Expand Down