You are here

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

Same name and namespace in other branches
  1. 5.x tests/src/Functional/RolesNegotiationFunctionalTest.php \Drupal\Tests\simple_oauth\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 tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own unpublished node but with missing scope.
RolesNegotiationFunctionalTest::testRequestWithRoleRemovedFromClient in tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own unpublished node but with the role removed from client.
RolesNegotiationFunctionalTest::testRequestWithRoleRemovedFromUser in tests/src/Functional/RolesNegotiationFunctionalTest.php
Test access to own published node with missing role on User entity.

File

tests/src/Functional/RolesNegotiationFunctionalTest.php, line 285

Class

RolesNegotiationFunctionalTest
Tests for the roles negotiation.

Namespace

Drupal\Tests\simple_oauth\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;
}