0

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?

Angelo Giuffredi
  • 923
  • 3
  • 13
  • 26
  • what grant_type was used? – bigmax Oct 18 '13 at 15:50
  • For now: `--grant-type="authorization_code"` `--grant-type="password"` `--grant-type="refresh_token"` `--grant-type="token"` `--grant-type="client_credentials"` And request was performed with `grant_type=password` – Angelo Giuffredi Oct 18 '13 at 16:49

2 Answers2

1

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.

AlexHalkin
  • 1,088
  • 14
  • 33
1

Try this:

$user = $this->get('security.token_storage')->getToken()->getUser();
DaanBuit
  • 74
  • 1
  • 6