Reputation: 823
My Request goes through a ApiUserAuthenticator extends AbstractGuardAuthenticator
to authenticate a request to an API. In the getUser() method I return an ApiUser.
public function getUser($credentials, UserProviderInterface $userProvider)
{
return new ApiUser('jean', ['ROLE_API_USER'], '[email protected]');
}
it works well because the user appears a little further in my controller.
/**
* @Route("/", name="API_INDEX")
*/
public function index()
{
dump($this->getUser());
return $this->json([
'status' => true,
]);
}
But a small detail is wrong, the username is missing ! It returns null.
Of course in the simplistic ApiUser the constructor & getter are ok.
This curious phenomenon disappears when you send back a Security\Core\User
object !
interesting isn't it ?
public function getUser($credentials, UserProviderInterface $userProvider)
{
return new \Symfony\Component\Security\Core\User\User('nicolas','0000',['ROLE_API_USER']);
}
Upvotes: 2
Views: 159