You are here

public function KeycloakController::logout in Keycloak OpenID Connect 8

Log out the current user.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse A redirect to either Keycloak or the front page.

1 string reference to 'KeycloakController::logout'
keycloak.routing.yml in ./keycloak.routing.yml
keycloak.routing.yml

File

src/Controller/KeycloakController.php, line 124

Class

KeycloakController
Keycloak controller.

Namespace

Drupal\keycloak\Controller

Code

public function logout() {
  $rp_signout = NULL;
  if (!$this->requestStack
    ->getCurrentRequest()->query
    ->get('op_initiated') && $this->keycloak
    ->isEnabled() && $this->keycloak
    ->isKeycloakUser() && $this->keycloak
    ->isKeycloakSignOutEnabled()) {
    $rp_signout = $this->keycloak
      ->getSessionInfo([
      KeycloakServiceInterface::KEYCLOAK_SESSION_ID_TOKEN,
    ]);
  }
  if ($this->currentUser
    ->isAuthenticated()) {
    user_logout();
  }
  if (!empty($rp_signout[KeycloakServiceInterface::KEYCLOAK_SESSION_ID_TOKEN])) {
    $response = $this->keycloak
      ->getKeycloakSignoutResponse($rp_signout);
    return $response;
  }
  return $this
    ->redirect('<front>');
}