You are here

protected function SamlController::createRedirectResponse in SAML Authentication 8.2

Converts a URL to a response object that is suitable for this controller.

Parameters

string|\Drupal\Core\Url $url: A URL to redirect to, either as a string or a Drupal URL object. Strings may only be used by callbacks that are configured in routing.yml as not being cacheable. (Which, in our case, is most callbacks.)

Return value

\Drupal\Core\Routing\TrustedRedirectResponse A response object representing a redirect.

6 calls to SamlController::createRedirectResponse()
SamlController::acs in src/Controller/SamlController.php
Attribute Consumer Service.
SamlController::changepw in src/Controller/SamlController.php
Change password redirector.
SamlController::login in src/Controller/SamlController.php
Initiates a SAML2 authentication flow.
SamlController::logout in src/Controller/SamlController.php
Initiate a SAML2 logout flow.
SamlController::metadata in src/Controller/SamlController.php
Displays service provider metadata XML for iDP autoconfiguration.

... See full list

File

src/Controller/SamlController.php, line 302

Class

SamlController
Returns responses for samlauth module routes.

Namespace

Drupal\samlauth\Controller

Code

protected function createRedirectResponse($url) {
  if (is_object($url)) {

    // If toString() is used without arguments, this influences requirements
    // for passing cacheability metadata into the response object, which can
    // lead to bugs (see #2630808 short description). We pass TRUE to get
    // cacheability metadata passed back in a GeneratedUrl object instead.
    $generated_url = $url
      ->toString(TRUE);
    $url = $generated_url
      ->getGeneratedUrl();
  }

  // Also when having returned from the IDP, we might redirect to an external
  // url (at least in theory), so we always return a TrustedRedirectResponse.
  $response = new TrustedRedirectResponse($url);
  if (isset($generated_url)) {

    // We shouldn't have to add cacheability metadata to our response object
    // when the route is configured to not cache responses in our routing.yml.
    // Do it anyway to prevent future obscure bugs with new routes.
    $response
      ->addCacheableDependency($generated_url);
  }
  return $response;
}