You are here

private function RolesNegotiationFunctionalTest::getAccessToken in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.2 simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php \Drupal\Tests\simple_oauth_extras\Functional\RolesNegotiationFunctionalTest::getAccessToken()

Return an access token.

Parameters

array $scopes: The scopes.

Return value

string The access token.

3 calls to RolesNegotiationFunctionalTest::getAccessToken()
RolesNegotiationFunctionalTest::testRequestWithMissingScope in simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own unpublished node but with missing scope.
RolesNegotiationFunctionalTest::testRequestWithRoleRemovedFromClient in simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own unpublished node but with the role removed from client.
RolesNegotiationFunctionalTest::testRequestWithRoleRemovedFromUser in simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own published node with missing role on User entity.

File

simple_oauth_extras/tests/src/Functional/RolesNegotiationFunctionalTest.php, line 269

Class

RolesNegotiationFunctionalTest
@group simple_oauth_extras

Namespace

Drupal\Tests\simple_oauth_extras\Functional

Code

private function getAccessToken(array $scopes = []) {
  $valid_payload = [
    'grant_type' => 'client_credentials',
    'client_id' => $this->client
      ->uuid(),
    'client_secret' => $this->clientSecret,
  ];
  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;
}