You are here

public function OAuth2ServerTestCase::testClientCredentialsGrantType in OAuth2 Server 7

Tests the "Client credentials" grant type.

File

tests/oauth2_server.test, line 271
OAuth2 tests.

Class

OAuth2ServerTestCase
Test basic API.

Code

public function testClientCredentialsGrantType() {
  $user = $this
    ->drupalCreateUser(array(
    'use oauth2 server',
  ));
  $this
    ->drupalLogin($user);
  $token_url = url('oauth2/token', array(
    'absolute' => TRUE,
  ));
  $data = array(
    'grant_type' => 'client_credentials',
  );
  $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);
  $this
    ->assertTokenResponse($response, FALSE);
}