You are here

public function KeycloakService::getKeycloakSignoutResponse in Keycloak OpenID Connect 8

Return a RP (Drupal) initiated single sign-out response.

Parameters

array $session_information: Session information array holding the required id_token.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect response redirecting to the sign out target route:

  • '<front>' if Keycloak single sign-out is disabled.
  • 'keycloak.logout' if Keycloak single sign-out is enabled.

Overrides KeycloakServiceInterface::getKeycloakSignoutResponse

File

src/Service/KeycloakService.php, line 280

Class

KeycloakService
Keycloak service.

Namespace

Drupal\keycloak\Service

Code

public function getKeycloakSignoutResponse(array $session_information) {
  $logout_redirect = Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])
    ->toString();
  if ($this
    ->isKeycloakSignOutEnabled() && !empty($session_information[self::KEYCLOAK_SESSION_ID_TOKEN])) {

    // We do an internal redirect here and modify it in
    // our KeycloakRequestSubscriber.
    return new RedirectResponse(Url::fromRoute('keycloak.logout', [], [
      'query' => [
        'id_token_hint' => $session_information[self::KEYCLOAK_SESSION_ID_TOKEN],
        'post_logout_redirect_uri' => $logout_redirect,
      ],
    ])
      ->toString());
  }
  return new RedirectResponse($logout_redirect);
}