You are here

public function Lockr::requestClientToken in Lockr 7.3

Requests a dev client token for a new or existing keyring.

Parameters

string $email:

string $password:

string $keyring_label:

string|null $client_label:

string|null $keyring_id:

File

vendor/lockr/lockr/src/Lockr.php, line 333

Class

Lockr

Namespace

Lockr

Code

public function requestClientToken($email, $password, $keyring_label, $client_label = null, $keyring_id = null) {
  $uri = (new Psr7\Uri())
    ->withScheme('https')
    ->withHost($this->accountsHost)
    ->withPath('/lockr-api/register');
  $data = [
    'email' => $email,
    'password' => $password,
    'keyring_label' => $keyring_label,
  ];
  if (!is_null($client_label)) {
    $data['client_label'] = $client_label;
  }
  if (!is_null($keyring_id)) {
    $data['keyring_id'] = $keyring_id;
  }
  $resp = $this->client
    ->getHttpClient()
    ->request('POST', $uri, [
    'headers' => [
      'content-type' => 'application/json',
      'accept' => 'application/json',
    ],
    'json' => $data,
    'timeout' => 30,
  ]);
  return json_decode((string) $resp
    ->getBody(), true);
}