AppserverIo\Appserver\ServletEngine\Authenticator\DigestAuthenticator::parse PHP Method

parse() protected method

Parses the request for the necessary, authentication adapter specific, login credentials.
protected parse ( AppserverIo\Psr\HttpMessage\RequestInterface $request ) : void
$request AppserverIo\Psr\HttpMessage\RequestInterface The request with the content of authentication data sent by client
return void
    protected function parse(RequestInterface $request)
    {
        // load the raw login credentials
        $rawAuthData = $request->getHeader(Protocol::HEADER_AUTHORIZATION);
        // init data and matches arrays
        $data = array();
        $matches = array();
        // define required data
        $requiredData = array('realm' => 1, 'nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1);
        // prepare key for parsing logic
        $key = implode('|', array_keys($requiredData));
        // parse header value
        preg_match_all('@(' . $key . ')=(?:([\'"])([^\\2]+?)\\2|([^\\s,]+))@', $rawAuthData, $matches, PREG_SET_ORDER);
        // iterate all found values for header value
        foreach ($matches as $match) {
            // check if match could be found
            if ($match[3]) {
                $data[$match[1]] = $match[3];
            } else {
                $data[$match[1]] = $match[4];
            }
            // unset required value because we got it processed
            unset($requiredData[$match[1]]);
        }
        // set if all required data was processed
        $data['method'] = $this->getRequestMethod();
        $this->authData = $requiredData ? false : $data;
    }