mariovalney / laravel-keycloak-web-guard

Simple Keycloak Guard to Laravel Web Routes - https://packagist.org/packages/vizir/laravel-keycloak-web-guard
146 stars 80 forks source link

Bug introduced by Keycloak 18+. #71

Open nunopedrosa opened 2 years ago

nunopedrosa commented 2 years ago

Keycloak 18 not longer supports redirect_uri parameter on logout and fails with an error: See: https://www.keycloak.org/docs/latest/upgrading/index.html#openid-connect-logout

So, in KeycloakService.php, getLogoutUrl should be something like:

public function getLogoutUrl() {
        $url = $this->getOpenIdValue('end_session_endpoint');

        if (empty($this->redirectLogout)) {
            $this->redirectLogout = url('/');
        }
        $params = [
            'client_id' => $this->getClientId(),
            #'redirect_uri' => $this->redirectLogout, # This is no longer supported and needs to be excluded
        ];
        $idToken= session()->get('keyIdToken'); # There is surely a better way to find the token...

        if (!empty($idToken)) {
            $params['post_logout_redirect_uri']= $this->redirectLogout; # These are the new optional Keycloak parameters
            $params['id_token_hint'] = $idToken; # These are the new optional Keycloak parameters
        }
        return $this->buildUrl($url, $params);
    }