protected function TokenBearerFunctionalTestBase::assertValidTokenResponse in Simple OAuth (OAuth2) & OpenID Connect 8.3
Same name and namespace in other branches
- 8.4 tests/src/Functional/TokenBearerFunctionalTestBase.php \Drupal\Tests\simple_oauth\Functional\TokenBearerFunctionalTestBase::assertValidTokenResponse()
- 8.2 tests/src/Functional/TokenBearerFunctionalTestBase.php \Drupal\Tests\simple_oauth\Functional\TokenBearerFunctionalTestBase::assertValidTokenResponse()
- 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.
Return value
array An array representing the response of "/oauth/token".
6 calls to TokenBearerFunctionalTestBase::assertValidTokenResponse()
- AuthCodeFunctionalTest::testAuthCodeGrant in simple_oauth_extras/
tests/ src/ Functional/ AuthCodeFunctionalTest.php - Test the valid AuthCode grant.
- AuthCodeFunctionalTest::testNon3rdPartyClientAuthCodeGrant in simple_oauth_extras/
tests/ src/ Functional/ AuthCodeFunctionalTest.php - Test the valid AuthCode grant if the client is non 3rd party.
- AuthCodeFunctionalTest::testRememberClient in simple_oauth_extras/
tests/ src/ Functional/ AuthCodeFunctionalTest.php - Tests the remember client functionality.
- 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.
File
- tests/
src/ Functional/ TokenBearerFunctionalTestBase.php, line 141
Class
- TokenBearerFunctionalTestBase
- Class TokenBearerFunctionalTestBase.
Namespace
Drupal\Tests\simple_oauth\FunctionalCode
protected function assertValidTokenResponse(ResponseInterface $response, $has_refresh = FALSE) {
$this
->assertEquals(200, $response
->getStatusCode());
$parsed_response = Json::decode((string) $response
->getBody());
$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
->assertFalse(isset($parsed_response['refresh_token']));
}
return $parsed_response;
}