You are here

public function CasProxyHelper::getProxyTicket in CAS 8

Same name and namespace in other branches
  1. 2.x src/Service/CasProxyHelper.php \Drupal\cas\Service\CasProxyHelper::getProxyTicket()

Get a proxy ticket using a proxy granting ticket.

Parameters

string $target_service: The service to be proxied.

Return value

string The proxy ticket returned by the CAS server.

Throws

\Drupal\cas\Exception\CasProxyException Thrown if there was a problem communicating with the CAS server.

1 call to CasProxyHelper::getProxyTicket()
CasProxyHelper::proxyAuthenticate in src/Service/CasProxyHelper.php
Proxy authenticates to a target service.

File

src/Service/CasProxyHelper.php, line 109

Class

CasProxyHelper
Class CasProxyHelper.

Namespace

Drupal\cas\Service

Code

public function getProxyTicket($target_service) {
  if (!($this->settings
    ->get('proxy.initialize') && $this->session
    ->has('cas_pgt'))) {

    // We can't perform proxy authentication in this state.
    throw new CasProxyException("Session state not sufficient for proxying.");
  }

  // Make request to CAS server to retrieve a proxy ticket for this service.
  $cas_url = $this
    ->getServerProxyUrl($target_service);
  try {
    $this->casHelper
      ->log(LogLevel::DEBUG, "Retrieving proxy ticket from %cas_url", [
      '%cas_url' => $cas_url,
    ]);

    // TODO: Consider allowing the config to be altered.
    $casServerConfig = CasServerConfig::createFromModuleConfig($this->settings);
    $casServerConnectionOptions = $casServerConfig
      ->getCasServerGuzzleConnectionOptions();
    $response = $this->httpClient
      ->get($cas_url, $casServerConnectionOptions);
  } catch (ClientException $e) {
    throw new CasProxyException($e
      ->getMessage());
  }
  $proxy_ticket = $this
    ->parseProxyTicket($response
    ->getBody());
  $this->casHelper
    ->log(LogLevel::DEBUG, "Extracted proxy ticket %ticket", [
    '%ticket' => $proxy_ticket,
  ]);
  return $proxy_ticket;
}