You are here

public function OAuth2ServerTestCase::testRefreshTokenGrantType in OAuth2 Server 7

Tests the "Refresh token" grant type.

File

tests/oauth2_server.test, line 341
OAuth2 tests.

Class

OAuth2ServerTestCase
Test basic API.

Code

public function testRefreshTokenGrantType() {

  // Do a password grant first, in order to get the refresh token.
  $result = $this
    ->passwordGrantRequest();
  $response = json_decode($result->data);
  $refresh_token = $response->refresh_token;
  $token_url = url('oauth2/token', array(
    'absolute' => TRUE,
  ));
  $data = array(
    'grant_type' => 'refresh_token',
    'refresh_token' => $refresh_token,
  );
  $options = array(
    'method' => 'POST',
    'data' => http_build_query($data),
    'headers' => array(
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Authorization' => 'Basic ' . base64_encode($this->client_key . ':' . $this->client_secret),
    ),
  );
  $result = $this
    ->httpRequest($token_url, $options);
  $this
    ->assertEqual($result->code, 200, 'The token request completed successfully');
  $response = json_decode($result->data);

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