You are here

public function RemoteManager::prepareClient in Entity Share 8

Same name and namespace in other branches
  1. 8.2 modules/entity_share_client/src/Service/RemoteManager.php \Drupal\entity_share_client\Service\RemoteManager::prepareClient()

Prepare an HTTP client authenticated to handle private files.

Parameters

\Drupal\entity_share_client\Entity\RemoteInterface $remote: The remote website on which to prepare the client.

Return value

\GuzzleHttp\Client An HTTP client with some info from the remote.

Overrides RemoteManagerInterface::prepareClient

File

modules/entity_share_client/src/Service/RemoteManager.php, line 38

Class

RemoteManager
Class RemoteManager.

Namespace

Drupal\entity_share_client\Service

Code

public function prepareClient(RemoteInterface $remote) {
  $http_client = $this->httpClientFactory
    ->fromOptions([
    'base_uri' => $remote
      ->get('url'),
    'cookies' => TRUE,
    'allow_redirects' => TRUE,
  ]);
  $http_client
    ->post('/user/login', [
    'form_params' => [
      'name' => $remote
        ->get('basic_auth_username'),
      'pass' => $remote
        ->get('basic_auth_password'),
      'form_id' => 'user_login_form',
    ],
  ]);
  return $http_client;
}