You are here

protected function OAuth2ServerTest::authorizationCodeRequest in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/OAuth2ServerTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerTest::authorizationCodeRequest()

Performs an authorization request and returns it.

Used to test authorization, the implicit flow, and the authorization_code grant type.

Parameters

string $response_type: The response type string.

string|null $scope: The scope string.

Return value

\Psr\Http\Message\ResponseInterface A response object.

Throws

\GuzzleHttp\Exception\GuzzleException

6 calls to OAuth2ServerTest::authorizationCodeRequest()
OAuth2ServerTest::testAuthorization in tests/src/Functional/OAuth2ServerTest.php
Tests the authorization part of the flow.
OAuth2ServerTest::testAuthorizationCodeGrantType in tests/src/Functional/OAuth2ServerTest.php
Tests the "Authorization code" grant type.
OAuth2ServerTest::testImplicitFlow in tests/src/Functional/OAuth2ServerTest.php
Tests the implicit flow.
OAuth2ServerTest::testOpenIdConnectAuthorizationCodeFlow in tests/src/Functional/OAuth2ServerTest.php
Tests the OpenID Connect authorization code flow.
OAuth2ServerTest::testOpenIdConnectImplicitFlow in tests/src/Functional/OAuth2ServerTest.php
Tests the OpenID Connect implicit flow.

... See full list

File

tests/src/Functional/OAuth2ServerTest.php, line 720

Class

OAuth2ServerTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

protected function authorizationCodeRequest($response_type, $scope = NULL) {
  $query = [
    'response_type' => $response_type,
    'client_id' => $this->clientId,
    'state' => Crypt::hmacBase64($this->clientId, Settings::getHashSalt()),
    'redirect_uri' => $this->redirectUri,
    // OpenID Connect requests require a nonce. Others ignore it.
    'nonce' => 'test',
  ];
  if ($scope) {
    $query['scope'] = $scope;
  }
  $url = new Url('oauth2_server.authorize');
  $cookieJar = $this
    ->getSessionCookies();
  $options = [
    'allow_redirects' => FALSE,
    'cookies' => $cookieJar,
    'query' => $query,
  ];
  return $this
    ->getHttpClient()
    ->request('GET', $url
    ->setAbsolute()
    ->toString(), $options);
}