I am attempting to create a logout function in Node.js with Nginx also running. For example, if a user accesses the logout URL, they should be redirected to a specific URL, such as the Keycloak endpoint.
function logout(r) {
r.log("[START] Logging out user session and terminating OIDC session.");
// Clear the access token cookie to log out the user
r.headersOut["Set-Cookie"] = "access_token=; Max-Age=0; Path=/";
// Terminate OIDC session by redirecting to the Keycloak logout URL
var keycloakLogoutUrl = "https://keycloak.com/auth/realms/xyz/protocol/openid-connect/logout";
r.return(302, keycloakLogoutUrl);
r.log("[FINISH] Logging out user session and terminating OIDC session.");
}
Nginx configuration :
location /logout { internal; # This location is only accessible internally
Some configuration with server
}