thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.
http://oauth2-client.thephpleague.com
MIT License
3.63k stars 751 forks source link

Oauth2 refresh problems #1011

Open Fearofthedark66 opened 9 months ago

Fearofthedark66 commented 9 months ago

Hi,

I am having trouble to refresh my tokens and I must be missing something here. With the code below I am getting a : ### Required parameter not passed: "refresh_token" error.

 $provider = new \League\OAuth2\Client\Provider\GenericProvider([
      'clientId'                => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',   
      'clientSecret'            => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
      'urlAuthorize'            => 'https://login.xero.com/identity/connect/authorize',
      'urlAccessToken'          => 'https://identity.xero.com/connect/token',
      'urlResourceOwnerDetails' => 'https://identity.xero.com/resources'
    ]);
$refreshToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$newAccessToken = $provider->getAccessToken('authorizaton_code', [
  'refresh_token' =>  $refreshToken,
  'grant_type' => 'authorization_code'
]);

`

Tamas-hi commented 9 months ago

I think the problem you are facing is coming from here:

You have added 'authorizaton_code' as the first parameter to $provider->getAccessToken, but you provide a $refreshToken instead of an $authCode.

Add 'refresh_token' as a first parameter to the $provider->getAccessToken and delete the 'grant_type' => 'authorization_code' row.