You are here

protected function TokenBearerFunctionalTestBase::assertValidTokenResponse in Simple OAuth (OAuth2) & OpenID Connect 8.2

Same name and namespace in other branches
  1. 8.4 tests/src/Functional/TokenBearerFunctionalTestBase.php \Drupal\Tests\simple_oauth\Functional\TokenBearerFunctionalTestBase::assertValidTokenResponse()
  2. 8.3 tests/src/Functional/TokenBearerFunctionalTestBase.php \Drupal\Tests\simple_oauth\Functional\TokenBearerFunctionalTestBase::assertValidTokenResponse()
  3. 5.x tests/src/Functional/TokenBearerFunctionalTestBase.php \Drupal\Tests\simple_oauth\Functional\TokenBearerFunctionalTestBase::assertValidTokenResponse()

Validates a valid token response.

Parameters

\Psr\Http\Message\ResponseInterface $response: The response object.

bool $has_refresh: TRUE if the response should return a refresh token. FALSE otherwise.

4 calls to TokenBearerFunctionalTestBase::assertValidTokenResponse()
AuthCodeFunctionalTest::testAuthCodeGrant in simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php
Test the valid AuthCode grant.
ClientCredentialsFunctionalTest::testClientCredentialsGrant in simple_oauth_extras/tests/src/Functional/ClientCredentialsFunctionalTest.php
Test the valid ClientCredentials grant.
PasswordFunctionalTest::testPasswordGrant in tests/src/Functional/PasswordFunctionalTest.php
Test the valid Password grant.
RefreshFunctionalTest::testRefreshGrant in simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php
Test the valid Refresh grant.

File

tests/src/Functional/TokenBearerFunctionalTestBase.php, line 162

Class

TokenBearerFunctionalTestBase
Class TokenBearerFunctionalTestBase

Namespace

Drupal\Tests\simple_oauth\Functional

Code

protected function assertValidTokenResponse(ResponseInterface $response, $has_refresh = FALSE) {
  $this
    ->assertEquals(200, $response
    ->getStatusCode());
  $parsed_response = Json::decode($response
    ->getBody()
    ->getContents());
  $this
    ->assertSame('Bearer', $parsed_response['token_type']);
  $expiration = $this
    ->config('simple_oauth.settings')
    ->get('access_token_expiration');
  $this
    ->assertLessThanOrEqual($expiration, $parsed_response['expires_in']);
  $this
    ->assertGreaterThanOrEqual($expiration - 10, $parsed_response['expires_in']);
  $this
    ->assertNotEmpty($parsed_response['access_token']);
  if ($has_refresh) {
    $this
      ->assertNotEmpty($parsed_response['refresh_token']);
  }
  else {
    $this
      ->assertTrue(empty($parsed_response['refresh_token']));
  }
}