You are here

protected static function JsonSubrequestDenormalizer::fixBasicAuth in Subrequests 3.x

Same name and namespace in other branches
  1. 8.2 src/Normalizer/JsonSubrequestDenormalizer.php \Drupal\subrequests\Normalizer\JsonSubrequestDenormalizer::fixBasicAuth()
  2. 8 src/Normalizer/JsonSubrequestDenormalizer.php \Drupal\subrequests\Normalizer\JsonSubrequestDenormalizer::fixBasicAuth()

Adds the decoded username and password headers for Basic Auth.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request to fix.

File

src/Normalizer/JsonSubrequestDenormalizer.php, line 127

Class

JsonSubrequestDenormalizer
Creates a request object for each Subrequest.

Namespace

Drupal\subrequests\Normalizer

Code

protected static function fixBasicAuth(Request $request) {

  // The server will not set the PHP_AUTH_USER and PHP_AUTH_PW for the
  // subrequests if needed.
  if ($request->headers
    ->has('Authorization')) {
    $header = $request->headers
      ->get('Authorization');
    if (strpos($header, 'Basic ') === 0) {
      list($user, $pass) = explode(':', base64_decode(substr($header, 6)));
      $request->headers
        ->set('PHP_AUTH_USER', $user);
      $request->headers
        ->set('PHP_AUTH_PW', $pass);
    }
  }
}