You are here

function _restclient_prepare_authentication in RESTClient 7.2

Prepare authentication for the request, if needed.

Parameters

array $variables [reference]: Array of URL variables ['authentication']['type'] indicates which type of authentication See _restclient_prepare_authentication_oauth2_client for additional settings when type is 'oauth2_client'.

Return value

boolean TRUE if authentication is ready or not needed, FALSE if there is an error.

2 calls to _restclient_prepare_authentication()
_restclient_request in ./restclient.module
Basic request with no body data.
_restclient_request_with_body in ./restclient.module
Requests with body data.

File

./restclient.module, line 854
Defines a standard REST interface to RESTful services

Code

function _restclient_prepare_authentication(&$variables) {

  // If authentication is not requested then return success.
  if (!isset($variables['authentication'])) {
    return TRUE;
  }

  // Prepare according to the authentication method.
  $return_value = FALSE;
  $authentication_type = '<unspecified>';
  if (isset($variables['authentication']['type'])) {
    $authentication_type = $variables['authentication']['type'];
  }
  switch ($authentication_type) {
    case 'oauth2_client':
      $return_value = _restclient_prepare_authentication_oauth2_client($variables);
      break;
    case 'hybridauth':
      $return_value = _restclient_prepare_authentication_hybridauth($variables);
      break;
    default:

      // The authentication method is not supported.
      watchdog('restclient', 'Authentication method "%type" is not supported.', array(
        '%type' => $authentication_type,
      ), WATCHDOG_ERROR);
      $return_value = FALSE;
      break;
  }
  return $return_value;
}