On logout from a specific tenant, redirect to the tenant landing page instead of the generic landing page.

Background

In Sunbird, if tenant is configured, for a logged in users, when they logout they are redirected to the generic landing page, instead of tenant landing page because the default keycloak logout function generates the logout URL as index page of Sunbird instance.

Now we should be provided the option of redirecting to the hostname/tenant_name.

for example: If tenant 'ap' is configured, then on logout, the user should be redirected to http://localhost/ap instead of http://localhost

Solution Overview

As per keycloak documentation, https://www.keycloak.org/docs/latest/securing_apps/index.html#installing-middleware

In Server.js 

app.use(keycloak.middleware({ admin: '/callback', logout: '/logout' }))

When 'logoff' route is called, the route '/logout' is called, with the help of the middleware we can redirect to the tenant landingpage URL. On passing the additional parameter to the logout route, we are able to send the url to the middle ware.

for Example: 'logout/ap', but the function which redirects to the logout url is not accepting the additional parameter '/ap'. this blocks the calling of the logoutUrl function.


Other way of achieving the redirection is to write the prototype of keycloak.logoutUrl function, where we can append the required tenant id '/ap' to the redirect URL.