I implemented FOSOAuthServerBundle in my application to provide an API for mobile application. It seems to work, the user gets the Token
and also the RefreshToken
but if I make the controller require the user object that always returns null
. Also fails the control of the permission, which is only IS_AUTHENTICATED_ANONIMOUSLY
.
example:
public function showUserAction(){
$user = $this->getUser()
//$user = null
$auth = $this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')
//$auth = false
}
How to get the user object in a controller with this type of authentication?
Based on your comment you have created client with different grant_types.
NOTE: If you use grant_type=client_credentials during authentication, there is no User available since you do not specify exact user/password for generating token. In case of grant_type=password you pass username & password and token is linked to user in this case. Hope this makes sense.