grav-plugin-admin icon indicating copy to clipboard operation
grav-plugin-admin copied to clipboard

onUserLogout Event redirect is not considered

Open an-ant0ni0 opened this issue 2 years ago • 0 comments

Currently a logout from admin always redirect to the baseurl of the admin (/admin as default).

For a site logout, there is a possibility to hook into the onUserLogout event and alter the redirect property of the UserLoginEvent. This event property will be considered for the redirect after logout. See here: https://github.com/getgrav/grav-plugin-login/blob/3.6.2/classes/Controller.php#L328-L331

We use this to call the logout callback of our auth service (keycloak).

As a workaround we hook with a custom plugin into the onTask.logout and do the redirect there:

    public static function getSubscribedEvents()
    {
        return [
            'onTask.logout' => ['onLogoutTask']
        ];
    }

    public function onLogoutTask()
    {
        $login = $this->grav['login'];

        $login->logout(['admin' => true]);
        $provider = \Grav\Plugin\Login\OAuth2\ProviderFactory::create('keycloak');
        $this->grav->redirect($provider->getLogoutUrl());
    }

Would you consider a change within the admin logout method to support the redirect property of the event as meaningful? I could provide a PR.

an-ant0ni0 avatar Mar 09 '22 21:03 an-ant0ni0