Neos\Flow\Security\Authentication\EntryPoint\HttpBasic::startAuthentication PHP Метод

startAuthentication() публичный Метод

Starts the authentication: Send HTTP header
public startAuthentication ( Request $request, Response $response ) : void
$request Neos\Flow\Http\Request The current request
$response Neos\Flow\Http\Response The current response
Результат void
    public function startAuthentication(Request $request, Response $response)
    {
        $response->setStatus(401);
        $response->setHeader('WWW-Authenticate', 'Basic realm="' . (isset($this->options['realm']) ? $this->options['realm'] : sha1(FLOW_PATH_ROOT)) . '"');
        $response->setContent('Authorization required');
    }

Usage Example

 /**
  * @test
  */
 public function startAuthenticationSetsTheCorrectValuesInTheResponseObject()
 {
     $mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
     $mockResponse = $this->getMockBuilder(Response::class)->getMock();
     $entryPoint = new HttpBasic();
     $entryPoint->setOptions(['realm' => 'realm string']);
     $mockResponse->expects($this->once())->method('setStatus')->with(401);
     $mockResponse->expects($this->once())->method('setHeader')->with('WWW-Authenticate', 'Basic realm="realm string"');
     $mockResponse->expects($this->once())->method('setContent')->with('Authorization required');
     $entryPoint->startAuthentication($mockHttpRequest, $mockResponse);
     $this->assertEquals(['realm' => 'realm string'], $entryPoint->getOptions());
 }