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

updateCredentials() public method

Note: You need to send the username and password in these two POST parameters: __authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][username] and __authentication[TYPO3][Flow][Security][Authentication][Token][UsernamePassword][password]
public updateCredentials ( ActionRequest $actionRequest ) : void
$actionRequest Neos\Flow\Mvc\ActionRequest The current action request
return void
    public function updateCredentials(ActionRequest $actionRequest)
    {
        $httpRequest = $actionRequest->getHttpRequest();
        if ($httpRequest->getMethod() !== 'POST') {
            return;
        }
        $arguments = $actionRequest->getInternalArguments();
        $username = ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.Flow.Security.Authentication.Token.UsernamePassword.username');
        $password = ObjectAccess::getPropertyPath($arguments, '__authentication.TYPO3.Flow.Security.Authentication.Token.UsernamePassword.password');
        if (!empty($username) && !empty($password)) {
            $this->credentials['username'] = $username;
            $this->credentials['password'] = $password;
            $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
        }
    }

Usage Example

 /**
  * @test
  */
 public function tokenCanBeCastToString()
 {
     $arguments = [];
     $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['username'] = '******';
     $arguments['__authentication']['TYPO3']['Flow']['Security']['Authentication']['Token']['UsernamePassword']['password'] = '******';
     $this->mockHttpRequest->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue('POST'));
     $this->mockActionRequest->expects($this->atLeastOnce())->method('getInternalArguments')->will($this->returnValue($arguments));
     $this->token->updateCredentials($this->mockActionRequest);
     $this->assertEquals('Username: "******"', (string) $this->token);
 }