protected function OAuth2ServerTest::passwordGrantRequest in OAuth2 Server 2.0.x
Same name and namespace in other branches
- 8 tests/src/Functional/OAuth2ServerTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerTest::passwordGrantRequest()
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
string|null $scope: An optional scope to request.
Return value
\Psr\Http\Message\ResponseInterface The return value of $this->httpRequest().
Throws
\Drupal\Core\Entity\EntityStorageException
\GuzzleHttp\Exception\GuzzleException
7 calls to OAuth2ServerTest::passwordGrantRequest()
- OAuth2ServerTest::testBlockedUserTokenFails in tests/
src/ Functional/ OAuth2ServerTest.php - Test that access is denied when using a token for a blocked user.
- OAuth2ServerTest::testCryptoTokens in tests/
src/ Functional/ OAuth2ServerTest.php - Tests crypto tokens.
- OAuth2ServerTest::testOpenIdConnectNonDefaultSub in tests/
src/ Functional/ OAuth2ServerTest.php - Tests that the OpenID Connect 'sub' property affects user info 'sub' claim.
- OAuth2ServerTest::testPasswordGrantType in tests/
src/ Functional/ OAuth2ServerTest.php - Tests the "User credentials" grant type.
- OAuth2ServerTest::testRefreshTokenGrantType in tests/
src/ Functional/ OAuth2ServerTest.php - Tests the "Refresh token" grant type.
File
- tests/
src/ Functional/ OAuth2ServerTest.php, line 763
Class
- OAuth2ServerTest
- The OAuth2 Server admin test case.
Namespace
Drupal\Tests\oauth2_server\FunctionalCode
protected function passwordGrantRequest($scope = NULL) {
$user = $this
->drupalCreateUser([
'use oauth2 server',
]);
$this
->drupalLogin($user);
$token_url = $this
->buildUrl(new Url('oauth2_server.token'));
$data = [
'grant_type' => 'password',
'username' => $user->name
->getValue()[0]['value'],
'password' => $user->pass_raw,
];
if ($scope) {
$data['scope'] = $scope;
}
return $this
->httpPostRequest($token_url, $data);
}