Php Symfony Guard或Userprovider-用户名始终为空
我的请求通过Php Symfony Guard或Userprovider-用户名始终为空,php,security,authentication,symfony4,guard,Php,Security,Authentication,Symfony4,Guard,我的请求通过ApiUserAuthenticator扩展AbstractGuardAuthenticator来验证对API的请求。在getUser()方法中,我返回一个ApiUser 公共函数getUser($credentials,UserProviderInterface$userProvider) { 返回新ApiUser('jean',['ROLE\u API\u USER'],'jean@bonnaud.fr'); } 它工作得很好,因为用户在我的控制器中显示得更远一些 /** *@
ApiUserAuthenticator扩展AbstractGuardAuthenticator
来验证对API的请求。在getUser()方法中,我返回一个ApiUser
公共函数getUser($credentials,UserProviderInterface$userProvider)
{
返回新ApiUser('jean',['ROLE\u API\u USER'],'jean@bonnaud.fr');
}
它工作得很好,因为用户在我的控制器中显示得更远一些
/**
*@Route(“/”,name=“API_索引”)
*/
公共职能指数()
{
转储($this->getUser());
返回$this->json([
“状态”=>true,
]);
}
但是一个小细节是错误的,用户名丢失了!它返回null
当然,在过于简单的ApiUser中,构造函数和getter是可以的。当您发回
Security\Core\User
对象时,这种奇怪的现象就会消失!
很有趣,不是吗
公共函数getUser($credentials,UserProviderInterface$userProvider)
{
返回新的\Symfony\Component\Security\Core\User\User('nicolas','0000',['ROLE\u API\u User']);
}