public function OAuth2ServerTest::testAuthorizationCodeGrantType 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::testAuthorizationCodeGrantType()
Tests the "Authorization code" grant type.
File
- tests/
src/ Functional/ OAuth2ServerTest.php, line 227
Class
- OAuth2ServerTest
- The OAuth2 Server admin test case.
Namespace
Drupal\Tests\oauth2_server\FunctionalCode
public function testAuthorizationCodeGrantType() {
$user = $this
->drupalCreateUser([
'use oauth2 server',
]);
$this
->drupalLogin($user);
// Perform authorization and get the code.
$response = $this
->authorizationCodeRequest('code');
$redirect_url_params = $this
->getRedirectParams($response);
$authorization_code = $redirect_url_params['code'];
$token_url = $this
->buildUrl(new Url('oauth2_server.token'));
$data = [
'grant_type' => 'authorization_code',
'code' => $authorization_code,
'redirect_uri' => $this->redirectUri,
];
$response = $this
->httpPostRequest($token_url, $data);
$this
->assertEqual($response
->getStatusCode(), 200, 'The token request completed successfully');
$payload = json_decode($response
->getBody());
$this
->assertTokenResponse($payload);
}