Symfony 2.3 getRequest()->标头未显示授权承载令牌 [英] Symfony 2.3 getRequest()->headers not showing Authorization Bearer Token

查看:90
本文介绍了Symfony 2.3 getRequest()->标头未显示授权承载令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Authorization:Bearer {Token}作为HTTP请求传递给我的Symfony Rest Controller.

I am passing an Authorization: Bearer { Token } as a HTTP request to my Symfony Rest Controller.

我的请求:

GET /app_dev.php/api/members HTTP/1.1
Host: localhost
Authorization: Bearer 123456789
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

在我的控制器内部:

$this->getRequest()->headers;

由于某些原因,当我使用Symfony的Request方法时,Authorization标头对我的控制器不可用.当我使用PHP的getallheaders()时,授权标题会按预期显示.关于为何Symfony无法看到的任何想法?

For some reason when I use Symfony's Request method the Authorization header isn't available to my controller. When I use PHP's getallheaders() the Authorization header shows up as expected. Any Ideas on why Symfony isn't seeing it?

谢谢

推荐答案

它很可能被Apache剥离了. Bearer不是已知方案,它是专有的.

It is most likely stripped by Apache. Bearer is not a known scheme, it is sort of proprietary.

因此,您可以使用自定义标头(例如X-Bearer-Token: 123456789),也可以尝试在.htaccess

Therefore, either you use a custom header, like X-Bearer-Token: 123456789 or you can try to add this rewrite condition in your .htaccess

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

这篇关于Symfony 2.3 getRequest()->标头未显示授权承载令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆