为什么我没有收到身份验证令牌错误? [英] Why I am getting no authentication token error?
问题描述
我有以下代码片段来检查使用角色,但它返回给我一个
I have the folowing snippet of code to check use role however it returns me with a
安全上下文不包含身份验证令牌.一个可能的原因可能是没有为此 URL 配置防火墙.
The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.
public function loginAction(){
$request = $this->getRequest();
$session = $request->getSession();
var_dump($this->get("security.context")->isGranted('ROLE_ADMIN'));
$response = new Response();
$response -> setContent("login facebook");
$response->send();
return array('name'=>'login facebook');
}
为什么我会收到这个错误,我该如何解决?
Why I am getting this error and how do I fix this ?
推荐答案
异常消息非常清楚:一个可能的原因可能是没有为此 URL 配置防火墙
.要检查用户角色,您需要一个包含用户(匿名与否)的令牌.默认情况下,如果您没有为给定路径配置身份验证提供程序,您将不会获得任何安全上下文.
The exception message is pretty clear: One possible reason may be that there is no firewall configured for this URL
. To check user role, you need a token which contains a user (anonymous or not). By default, if you don't configure a authentication provider for a given path, you won't get any security context.
这里的解决方案是添加身份验证提供程序.
The solution here is to add an authentication provider.
这篇关于为什么我没有收到身份验证令牌错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!