You are here

function _restclient_authentication_hybridauth_request_error in RESTClient 7.2

1 call to _restclient_authentication_hybridauth_request_error()
_restclient_authentication_request_error in ./restclient.module
Handle authentication-related request errors, and indicate if the request can be retried. This can be the case for situations where the token had expired: we re-authenticate and indicate that the request can be re-attempted.

File

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

Code

function _restclient_authentication_hybridauth_request_error($response, $variables) {
  if ($response->code == '401') {
    if ($response->headers['content-type'] == 'application/json') {
      $data = drupal_json_decode($response->data);
      if (!empty($data['error']) and ($data['error'] == 'expired_token' or $data['error'] = 'invalid_token')) {
        $hybridauth_instance = hybridauth_get_instance();
        $hybridauth_client_id = $variables['authentication']['hybridauth']['client_id'];
        $hybridauth_adapter = $hybridauth_instance
          ->getAdapter($hybridauth_client_id);
        $hybridauth_adapter
          ->logout();
        $hybridauth_instance
          ->authenticate($hybridauth_client_id);
        return TRUE;
      }
    }
  }
  return FALSE;
}