You are here

function clients_connection_drupal_services_7_3::getXCSRFToken in Web Service Clients 7.3

Get the X-CSRF token.

This calls the remote site to get the token, and caches it, so that multiple requests made with the same connection don't need to retrieve it again.

This expects the 'user.token' method to be enabled on the endpoint. This only exists in Services 3.5 and later. We do not support earlier versions.

Return value

The X-CSRF token.

Throws

An exception if the remote site does not return a token.

1 call to clients_connection_drupal_services_7_3::getXCSRFToken()
clients_connection_drupal_services_7_3::callMethodArray in connections/clients_drupal/clients_drupal.inc
Call a remote method.

File

connections/clients_drupal/clients_drupal.inc, line 212
Contains classes for Client connections handlers.

Class

clients_connection_drupal_services_7_3
Drupal client for services on a Drupal 7 site for Services 7.x-3.x.

Code

function getXCSRFToken() {
  if (isset($this->CSRFToken)) {
    return $this->CSRFToken;
  }
  $headers = array(
    // Pass in the login cookie we received previously.
    'Cookie' => $this->cookie,
  );
  $options = array(
    'headers' => $headers,
  );
  $response = xmlrpc($this->endpoint, array(
    'user.token' => array(),
  ), $options);
  $this
    ->handleXmlrpcError();
  if (isset($response['token'])) {
    $this->CSRFToken = $response['token'];
    return $this->CSRFToken;
  }
  else {
    throw new Exception(t("Unable to get a CSRF token from the remote site."));
  }
}