You are here

protected function ConsumerConfigTest::getAccessToken in farmOS 2.x

Return an access token.

Parameters

array $scopes: The scopes.

Return value

string The access token.

3 calls to ConsumerConfigTest::getAccessToken()
ConsumerConfigTest::testGrantUserAccess in modules/core/api/tests/src/Functional/ConsumerConfigTest.php
Test consumer.grant_user_access config.
ConsumerConfigTest::testLimitRequestedAccess in modules/core/api/tests/src/Functional/ConsumerConfigTest.php
Test consumer.limit_requested_access.
ConsumerConfigTest::testLimitUserAccess in modules/core/api/tests/src/Functional/ConsumerConfigTest.php
Test consumer.limit_user_access.

File

modules/core/api/tests/src/Functional/ConsumerConfigTest.php, line 265

Class

ConsumerConfigTest
Tests using the consumer.client_id field.

Namespace

Drupal\Tests\farm_api\Functional

Code

protected function getAccessToken(array $scopes = []) {
  $valid_payload = [
    'grant_type' => 'password',
    'client_id' => $this->client
      ->get('client_id')->value,
    'username' => $this->user
      ->getAccountName(),
    'password' => $this->user->pass_raw,
  ];
  if (!empty($scopes)) {
    $valid_payload['scope'] = implode(' ', $scopes);
  }
  $response = $this
    ->post($this->url, $valid_payload);
  $parsed_response = Json::decode((string) $response
    ->getBody());
  return isset($parsed_response['access_token']) ? $parsed_response['access_token'] : NULL;
}