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

do an idp logout even when oidc.isAuthenticated is false #640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 29 additions & 12 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,31 @@ class ResponseContext {
try {
const { client } = await getClient(config);

/**
* Generates the logout URL.
*
* Depending on the configuration, this function will either perform a local only logout
* or a federated logout by redirecting to the appropriate URL.
*
* @param {string} idTokenHint - The ID token hint to be used for the logout request.
* @returns {string} The URL to redirect the user to for logout.
*/
const getLogoutUrl = (idTokenHint) => {
// if idpLogout is not configured, perform a local only logout
if (!config.idpLogout) {
debug('performing a local only logout, redirecting to %s', returnURL);
return returnURL;
}

// if idpLogout is configured, perform a federated logout
return client.endSessionUrl({
...config.logoutParams,
...(idTokenHint && { id_token_hint: idTokenHint }),
post_logout_redirect_uri: returnURL,
...params.logoutParams,
});
};

if (url.parse(returnURL).host === null) {
returnURL = urlJoin(config.baseURL, returnURL);
}
Expand All @@ -311,23 +336,15 @@ class ResponseContext {

if (!req.oidc.isAuthenticated()) {
debug('end-user already logged out, redirecting to %s', returnURL);
return res.redirect(returnURL);

// perform idp logout with no token hint
return res.redirect(getLogoutUrl(undefined));
}

const { idToken: id_token_hint } = req.oidc;
req[config.session.name] = undefined;

if (!config.idpLogout) {
debug('performing a local only logout, redirecting to %s', returnURL);
return res.redirect(returnURL);
}

returnURL = client.endSessionUrl({
...config.logoutParams,
id_token_hint,
post_logout_redirect_uri: returnURL,
...params.logoutParams,
});
returnURL = getLogoutUrl(id_token_hint);
} catch (err) {
return next(err);
}
Expand Down
Loading