You are here

public function OAuth2ServerTest::testRefreshTokenGrantType in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/OAuth2ServerTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerTest::testRefreshTokenGrantType()

Tests the "Refresh token" grant type.

File

tests/src/Functional/OAuth2ServerTest.php, line 311

Class

OAuth2ServerTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

public function testRefreshTokenGrantType() {

  // Do a password grant first, in order to get the refresh token.
  $response = $this
    ->passwordGrantRequest();
  $payload = json_decode($response
    ->getBody());
  $refresh_token = $payload->refresh_token;
  $token_url = $this
    ->buildUrl(new Url('oauth2_server.token'));
  $data = [
    'grant_type' => 'refresh_token',
    'refresh_token' => $refresh_token,
  ];
  $response = $this
    ->httpPostRequest($token_url, $data);
  $this
    ->assertEqual($response
    ->getStatusCode(), 200, 'The token request completed successfully');
  $payload = json_decode($response
    ->getBody());

  // The response will include a new refresh_token because
  // always_issue_new_refresh_token is TRUE.
  $this
    ->assertTokenResponse($payload);
}