lithium\net\http\Auth::decode PHP Method

decode() public static method

Takes the header string and parses out the params needed for a digest authentication.
public static decode ( string $header ) : array
$header string
return array
    public static function decode($header)
    {
        $data = array('realm' => null, 'username' => null, 'uri' => null, 'nonce' => null, 'opaque' => null, 'qop' => null, 'cnonce' => null, 'nc' => null, 'response' => null);
        $keys = implode('|', array_keys($data));
        $regex = '@(' . $keys . ')=(?:([\'"])([^\\2]+?)\\2|([^\\s,]+))@';
        preg_match_all($regex, $header, $matches, PREG_SET_ORDER);
        foreach ($matches as $m) {
            if (!isset($m[3]) && !isset($m[4])) {
                continue;
            }
            $data[$m[1]] = $m[3] ? $m[3] : $m[4];
        }
        return $data;
    }

Usage Example

Beispiel #1
0
 public function testDecode()
 {
     $header = 'qop="auth",nonce="4bca0fbca7bd0",' . 'nc="00000001",cnonce="95b2cd1e179bf5414e52ed62811481cf",' . 'uri="/http_auth",realm="app",' . 'opaque="d3fb67a7aa4d887ec4bf83040a820a46",username="******",' . 'response="04d7d878c67f289f37e553d2025e3a52"';
     $expected = array('qop' => 'auth', 'nonce' => '4bca0fbca7bd0', 'nc' => '00000001', 'cnonce' => '95b2cd1e179bf5414e52ed62811481cf', 'uri' => '/http_auth', 'realm' => 'app', 'opaque' => 'd3fb67a7aa4d887ec4bf83040a820a46', 'username' => 'gwoo', 'response' => '04d7d878c67f289f37e553d2025e3a52');
     $result = Auth::decode($header);
     $this->assertEqual($expected, $result);
 }