请求标头包在 Symfony 2 中缺少授权标头?

2022-08-30 11:05:58

我正在尝试在Symfony 2中实现自定义身份验证提供程序。我正在使用Fiddler发送测试请求并打印所有标头服务器端;好吧,标头丢失了。Authorization

我做错了什么吗?

GET /RESTfulBackend/web/index.php HTTP/1.1
Authorization: FID 44CF9590006BF252F707:jZNOcbfWmD/
Host: localhost
User-Agent: Fiddler
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3

侦听器只需打印标头并退出:

class HMACListener implements ListenerInterface
{
    private $securityContext;

    private $authenticationManager;

    public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        print_r($request->headers->all()); 
        die();
     }
}

响应缺少标头:Authorization

Array
(
    [host] => Array
        (
            [0] => localhost
        )
    [user-agent] => Array
        (
            [0] => Fiddler
        )
    [accept] => Array
        (
            [0] => text/html,application/xhtml+xml,application/xml
        )
    [accept-language] => Array
        (
            [0] => it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
        )
)

答案 1

您必须将此代码添加到虚拟主机标记

如果将其放在目录标记中,它将不起作用。

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

答案 2

Akambi的答案对我不起作用,但在php网站上找到了这个答案:

“CGI/FastCGI Apache下缺少授权标头的解决方法:

SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0

现在,如果客户端发送授权标头,PHP应该自动声明$_SERVER[PHP_AUTH_*]变量。

感谢 derkontrollfreak+9hy5l!


推荐