You are here

public function OAuth2ServerTest::httpPostRequest 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::httpPostRequest()

Perform a POST request.

Parameters

string $url: A Url object.

array $data: A data array.

bool $authorization: Whether to authorize the request.

Return value

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

Throws

\GuzzleHttp\Exception\GuzzleException

7 calls to OAuth2ServerTest::httpPostRequest()
OAuth2ServerTest::passwordGrantRequest in tests/src/Functional/OAuth2ServerTest.php
Performs a password grant request and returns it.
OAuth2ServerTest::testAuthorizationCodeGrantType in tests/src/Functional/OAuth2ServerTest.php
Tests the "Authorization code" grant type.
OAuth2ServerTest::testClientCredentialsGrantType in tests/src/Functional/OAuth2ServerTest.php
Tests the "Client credentials" grant type.
OAuth2ServerTest::testJwtBearerGrantType in tests/src/Functional/OAuth2ServerTest.php
Tests the "JWT bearer" grant type.
OAuth2ServerTest::testOpenIdConnectAuthorizationCodeFlow in tests/src/Functional/OAuth2ServerTest.php
Tests the OpenID Connect authorization code flow.

... See full list

File

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

Class

OAuth2ServerTest
The OAuth2 Server admin test case.

Namespace

Drupal\Tests\oauth2_server\Functional

Code

public function httpPostRequest($url, array $data = [], $authorization = TRUE) {
  $cookieJar = $this
    ->getSessionCookies();
  $options = [
    'cookies' => $cookieJar,
    'allow_redirects' => FALSE,
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/x-www-form-urlencoded',
    ],
    'form_params' => $data,
    'debug' => FALSE,
  ];
  if ($authorization) {
    $options['headers']['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
  }
  return $this
    ->getHttpClient()
    ->request('POST', $url, $options);
}