phpsymfonyoauth-2.0fosuserbundlefosrestbundle

Get a new token with the refresh token symfony oauth2


I work on symfony project with FriendsOfSymfony/FOSRestBundle, FriendsOfSymfony/FOSUserBundle and FriendsOfSymfony/FOSOAuthServerBundle.

In the security part, I can't get my new access token with using the refresh token. I can only get my access token. I have followed some tutorials and I got this error when I try to get a new token:

{
   "error": "unauthorized_client",
   "error_description": "Le type de subvention est non autorisee pour cette client_id"
}

The url is: http://myproject.local/oauth/v2/token

The params are :

  • grant_type: refresh_token
  • client_id: client_id
  • client_secret: client_secret
  • refresh_token: refresh_token

Did I missed any configuration? Or the I used a wrong url or a wrong params? Any help please?


Solution

  • The error indicates that your client is not allowed to use the refresh_token grant type. What you have to do is to add this grant type to your client (code not tested):

    $clientManager = $this->container->get('fos_oauth_server.client_manager.default'); // Get the Client manager
    $client = $clientManager->findClientByPublicId('PUBLIC ID OF YOUR CLIENT HERE'); // Get the Client
    $grant = $client->getAllowedGrantTypes(); // Get the grant types
    $grant[] = 'refresh_token'; // Add the refresh_token grant type
    $client->setAllowedGrantTypes($grant); // Modify your Client
    $clientManager->updateClient($client); // Save your Client