Skip to content

Set a custom redirect url for the user and use it in the logoutAction() #5462

@moreamazingnick

Description

@moreamazingnick

Is your feature request related to a problem? Please describe.

For a feature in our OIDC module I need to redirect to a different Url on logout.

Describe the solution you'd like

The Logout action currently redirects to login after logout.

    public function logoutAction()
    {
        $auth = $this->Auth();
        if (! $auth->isAuthenticated()) {
            $this->redirectToLogin();
        }
        // Get info whether the user is externally authenticated before removing authorization which destroys the
        // session and the user object
        $isExternalUser = $auth->getUser()->isExternalUser();
        // Call provided AuthenticationHook(s) when logout action is called
        AuthenticationHook::triggerLogout($auth->getUser());
        $auth->removeAuthorization();
        if ($isExternalUser) {
            $this->view->layout()->setLayout('external-logout');
            $this->getResponse()->setHttpResponseCode(401);
        } else {
            if (RememberMe::hasCookie() && $this->hasDb()) {
                $this->getResponse()->setCookie(RememberMe::forget());
            }

            $this->redirectToLogin();
        }
    }

I would like to suggest to allow to set a redirect url for the user with like:

$user->setAdditional('logout-url',"customurl to any logout page")

With this a custom backend could redirect to any url even an oidc logout-url

and in the logoutAction() we would fetch the url with:

$user->getAdditional('logout-url')

and redirect to this locations.

Describe alternatives you've considered

Since the AuthenticationHook::triggerLogout() is called before I could use a Hook to do the redirect which of course prevents from executing any other onLogout() after the OIDC onLogout().

Overriding the whole logout function in the Controller is something I do not want to do.

A priority on the hooks would work for my case and would be a suitable alternative. This at least increases the probability of executing other hooks.

Additional context

This works as a POC of an oidc relogin (RISE-GmbH/icingaweb2-module-oidc#18) which would improve the user experience significantly.
I also added the experimental feature in oidc 0.7.3 which uses the hook but with the comment that this should not be enabled if any other module uses an onlogout function in their AuthenticationHook

Best Regards
Nicolas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions