Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony Guard或Userprovider-用户名始终为空_Php_Security_Authentication_Symfony4_Guard - Fatal编程技术网

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']); }