Neos\Flow\Security\Authentication\Token\UsernamePasswordHttpBasic::updateCredentials PHP Method

updateCredentials() public method

Sets the authentication status to AUTHENTICATION_NEEDED, if the header has been sent, to NO_CREDENTIALS_GIVEN if no authorization header was there.
public updateCredentials ( ActionRequest $actionRequest ) : void
$actionRequest Neos\Flow\Mvc\ActionRequest The current action request instance
return void
    public function updateCredentials(ActionRequest $actionRequest)
    {
        $authorizationHeader = $actionRequest->getHttpRequest()->getHeaders()->get('Authorization');
        if (substr($authorizationHeader, 0, 5) === 'Basic') {
            $credentials = base64_decode(substr($authorizationHeader, 6));
            $this->credentials['username'] = substr($credentials, 0, strpos($credentials, ':'));
            $this->credentials['password'] = substr($credentials, strpos($credentials, ':') + 1);
            $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
        } else {
            $this->credentials = ['username' => null, 'password' => null];
            $this->authenticationStatus = self::NO_CREDENTIALS_GIVEN;
        }
    }

Usage Example

 /**
  * @test
  */
 public function updateCredentialsSetsTheCorrectAuthenticationStatusIfNoCredentialsArrived()
 {
     $httpRequest = Request::create(new Uri('http://foo.com'));
     $mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
     $mockActionRequest->expects($this->atLeastOnce())->method('getHttpRequest')->will($this->returnValue($httpRequest));
     $this->token->updateCredentials($mockActionRequest);
     $this->assertSame(TokenInterface::NO_CREDENTIALS_GIVEN, $this->token->getAuthenticationStatus());
 }
UsernamePasswordHttpBasic