lithium\net\http\Auth::decode()

public static method

Takes the header string and parses out the params needed for a digest authentication.

Parameters

  • string $header

Returns

array

Source

	public static function decode($header) {
		$data = [
			'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;
	}