You are here

protected function OAuth2ServerTestCase::passwordGrantRequest in OAuth2 Server 7

Performs a password grant request and returns it.

Used to test the grant itself, as well as a helper for other tests (since it's a fast way of getting an access token).

Parameters

$scope: An optional scope to request.

Return value

The return value of $this->httpRequest().

8 calls to OAuth2ServerTestCase::passwordGrantRequest()
OAuth2ServerTestCase::testBlockedUserTokenFails in tests/oauth2_server.test
Test that access is denied when using a token for a blocked user.
OAuth2ServerTestCase::testCryptoTokens in tests/oauth2_server.test
Tests crypto tokens.
OAuth2ServerTestCase::testOpenIdConnectNonDefaultSub in tests/oauth2_server.test
Tests that the OpenID Connect 'sub' property affects user info 'sub' claim.
OAuth2ServerTestCase::testPasswordGrantType in tests/oauth2_server.test
Tests the "User credentials" grant type.
OAuth2ServerTestCase::testRefreshTokenGrantType in tests/oauth2_server.test
Tests the "Refresh token" grant type.

... See full list

File

tests/oauth2_server.test, line 739
OAuth2 tests.

Class

OAuth2ServerTestCase
Test basic API.

Code

protected function passwordGrantRequest($scope = NULL) {
  $user = $this
    ->drupalCreateUser(array(
    'use oauth2 server',
  ));
  $this
    ->drupalLogin($user);
  $token_url = url('oauth2/token', array(
    'absolute' => TRUE,
  ));
  $data = array(
    'grant_type' => 'password',
    'username' => $user->name,
    'password' => $user->pass_raw,
  );
  if ($scope) {
    $data['scope'] = $scope;
  }
  $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),
    ),
  );
  return $this
    ->httpRequest($token_url, $options);
}