You are here

protected function KeycloakRouteSubscriber::alterRoutes in Keycloak OpenID Connect 8

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

src/Routing/KeycloakRouteSubscriber.php, line 35

Class

KeycloakRouteSubscriber
Listens to dynamic route events.

Namespace

Drupal\keycloak\Routing

Code

protected function alterRoutes(RouteCollection $collection) {

  // Whether the Keycloak client is disabled.
  if (!$this->keycloak
    ->isEnabled()) {
    return;
  }

  // Whether Keycloak single sign-on is enabled.
  if ($this->keycloak
    ->isSsoEnabled() && ($route = $collection
    ->get('user.login'))) {
    $route
      ->setDefaults([
      '_controller' => '\\Drupal\\keycloak\\Controller\\KeycloakController::login',
    ])
      ->setOptions([
      '_maintenance_access' => TRUE,
      'no_cache' => TRUE,
    ]);
  }

  // Always grant access to '/user/logout' and delegate its
  // handling to our own controller.
  if (($this->keycloak
    ->isKeycloakSignOutEnabled() || $this->keycloak
    ->isCheckSessionEnabled()) && ($route = $collection
    ->get('user.logout'))) {
    $route
      ->setDefaults([
      '_controller' => '\\Drupal\\keycloak\\Controller\\KeycloakController::logout',
    ])
      ->setRequirements([
      '_access' => 'TRUE',
    ])
      ->setOptions([
      'no_cache' => TRUE,
    ]);
  }
}