You are here

public function BasicAuth::getClient in Entity Share 8.3

Prepares a guzzle client for http operations with the supported auth.

Parameters

string $url: The url to set in the client.

Return value

\GuzzleHttp\Client The HTTP client.

Overrides ClientAuthorizationInterface::getClient

File

modules/entity_share_client/src/Plugin/ClientAuthorization/BasicAuth.php, line 31

Class

BasicAuth
Provides Basic Auth based client authorization.

Namespace

Drupal\entity_share_client\Plugin\ClientAuthorization

Code

public function getClient($url) {
  $credentials = $this->keyService
    ->getCredentials($this);
  $http_client = $this->httpClientFactory
    ->fromOptions([
    'base_uri' => $url . '/',
    'cookies' => TRUE,
    'allow_redirects' => TRUE,
  ]);
  $http_client
    ->post('/user/login', [
    'form_params' => [
      'name' => $credentials['username'],
      'pass' => $credentials['password'],
      'form_id' => 'user_login_form',
    ],
  ]);
  return $http_client;
}