public function RefreshFunctionalTest::testRefreshGrant in Simple OAuth (OAuth2) & OpenID Connect 8.2
Same name and namespace in other branches
- 8.3 simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php \Drupal\Tests\simple_oauth_extras\Functional\RefreshFunctionalTest::testRefreshGrant()
Test the valid Refresh grant.
File
- simple_oauth_extras/
tests/ src/ Functional/ RefreshFunctionalTest.php, line 50
Class
- RefreshFunctionalTest
- @group simple_oauth_extras
Namespace
Drupal\Tests\simple_oauth_extras\FunctionalCode
public function testRefreshGrant() {
// 1. Test the valid response.
$valid_payload = [
'grant_type' => 'refresh_token',
'client_id' => $this->client
->uuid(),
'client_secret' => $this->clientSecret,
'refresh_token' => $this->refreshToken,
'scope' => $this->scope,
];
$response = $this
->request('POST', $this->url, [
'form_params' => $valid_payload,
]);
$this
->assertValidTokenResponse($response, TRUE);
// 2. Test the valid without scopes.
// We need to use the new refresh token, the old one is revoked.
$response
->getBody()
->rewind();
$parsed_response = Json::decode($response
->getBody()
->getContents());
$valid_payload = [
'grant_type' => 'refresh_token',
'client_id' => $this->client
->uuid(),
'client_secret' => $this->clientSecret,
'refresh_token' => $parsed_response['refresh_token'],
'scope' => $this->scope,
];
$response = $this
->request('POST', $this->url, [
'form_params' => $valid_payload,
]);
$this
->assertValidTokenResponse($response, TRUE);
// 3. Test that the token token was revoked.
$valid_payload = [
'grant_type' => 'refresh_token',
'client_id' => $this->client
->uuid(),
'client_secret' => $this->clientSecret,
'refresh_token' => $this->refreshToken,
];
$response = $this
->request('POST', $this->url, [
'form_params' => $valid_payload,
]);
$parsed_response = Json::decode($response
->getBody()
->getContents());
$this
->assertSame(401, $response
->getStatusCode());
$this
->assertSame('invalid_request', $parsed_response['error']);
}