public function PasswordFunctionalTest::testPasswordGrant in Simple OAuth (OAuth2) & OpenID Connect 8.2
Same name and namespace in other branches
- 8.4 tests/src/Functional/PasswordFunctionalTest.php \Drupal\Tests\simple_oauth\Functional\PasswordFunctionalTest::testPasswordGrant()
- 8.3 tests/src/Functional/PasswordFunctionalTest.php \Drupal\Tests\simple_oauth\Functional\PasswordFunctionalTest::testPasswordGrant()
- 5.x tests/src/Functional/PasswordFunctionalTest.php \Drupal\Tests\simple_oauth\Functional\PasswordFunctionalTest::testPasswordGrant()
Test the valid Password grant.
File
- tests/
src/ Functional/ PasswordFunctionalTest.php, line 20
Class
- PasswordFunctionalTest
- @group simple_oauth
Namespace
Drupal\Tests\simple_oauth\FunctionalCode
public function testPasswordGrant() {
// 1. Test the valid request.
$valid_payload = [
'grant_type' => 'password',
'client_id' => $this->client
->uuid(),
'client_secret' => $this->clientSecret,
'username' => $this->user
->getAccountName(),
'password' => $this->user->pass_raw,
'scope' => $this->scope,
];
$response = $this
->request('POST', $this->url, [
'form_params' => $valid_payload,
]);
$this
->assertValidTokenResponse($response, TRUE);
// 2. Test the valid request without scopes.
$payload_no_scope = $valid_payload;
unset($payload_no_scope['scope']);
$response = $this
->request('POST', $this->url, [
'form_params' => $payload_no_scope,
]);
$this
->assertValidTokenResponse($response, TRUE);
// 3. Test valid request using HTTP Basic Auth.
$payload_no_client = $valid_payload;
unset($payload_no_client['client_id']);
unset($payload_no_client['client_secret']);
$response = $this
->request('POST', $this->url, [
'form_params' => $payload_no_scope,
'auth' => [
$this->client
->uuid(),
$this->clientSecret,
],
]);
$this
->assertValidTokenResponse($response, TRUE);
}