You are here

public function OauthPasswordTest::testPasswordGrant in farmOS 2.x

Test a valid Password grant using username and email.

File

modules/core/login/tests/src/Functional/OauthPasswordTest.php, line 36

Class

OauthPasswordTest
Tests using an email with OAuth Password Grant.

Namespace

Druapl\tests\farm_login\Functional

Code

public function testPasswordGrant() {
  $valid_payload = [
    'grant_type' => 'password',
    'client_id' => $this->client
      ->get('client_id')->value,
    'username' => $this->user
      ->getAccountName(),
    'password' => $this->user->pass_raw,
    'scope' => $this->scope,
  ];

  // 1. Test the password grant with a username.
  $response = $this
    ->post($this->url, $valid_payload);
  $this
    ->assertValidTokenResponse($response, TRUE);

  // 2. Test the password grant with an email as the username.
  $payload_client_id = $valid_payload;
  $payload_client_id['username'] = $this->user
    ->getEmail();
  $response = $this
    ->post($this->url, $payload_client_id);
  $this
    ->assertValidTokenResponse($response, TRUE);
}