Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid_grant error #196

Closed
youwe opened this issue Dec 23, 2020 · 7 comments
Closed

Invalid_grant error #196

youwe opened this issue Dec 23, 2020 · 7 comments

Comments

@youwe
Copy link

youwe commented Dec 23, 2020

Does anyone know where this suddenly comes from.
It was working just fine, but suddenly after some updates the process died.

Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException: invalid_grant in /resources/fileshare/releases/20201223173700/htdocs/vendor/league/oauth2-client/src/Provider/GenericProvider.php:222 Stack trace: #0 /resources/fileshare/releases/20201223173700/htdocs/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(628): League\OAuth2\Client\Provider\GenericProvider->checkResponse(Object(GuzzleHttp\Psr7\Response), Array) #1 /resources/fileshare/releases/20201223173700/htdocs/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(537): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request)) #2 /resources/fileshare/releases/20201223173700/htdocs/rest/lib/xero/authorizedResource.php(29): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\RefreshToken), Array) #3 {main} thrown in /resources/fileshare/releases/20201223173700/htdocs/vendor/league/oauth2-client/src/Provider/GenericProvider.php on line 222

$newAccessToken = $_provider->getAccessToken('refresh_token', [
'refresh_token' => $this->_storage->getRefreshToken()
]);

@rodjsta
Copy link

rodjsta commented Dec 23, 2020

Hi @youwe,

It looks like you need to specify the grant_type when requesting the new access token.

image

You would also need to ensure you have offline_access included in your scopes.

For sanity, I would also check that the app is still connected from within Xero connected apps under settings.

@youwe
Copy link
Author

youwe commented Dec 23, 2020

Updated the code, but still the same issue.

$newAccessToken = $provider->getAccessToken('refresh_token', [
'grant_type' => 'refresh_token',
'refresh_token' => $storage->getRefreshToken()
]);

Offline_access was already added. And the app is still connected.

@rodjsta
Copy link

rodjsta commented Dec 23, 2020

@youwe try disconnecting the app completely and getting completely fresh tokens through the auth process again. You could then manually trigger the access token expiry and attempt this new code for a new access token.

@youwe
Copy link
Author

youwe commented Dec 23, 2020

Issue has been resolved. Seems the ID tokens of Xero have changed in format. So now with a base64 encoding the string became much longer and the storage column was not capable in storing the id length.

@sahilr2050
Copy link

@youwe What size of the column you have set to store the ID tokens?

Did you set TEXT type? or Varchar?

@rabinacharya
Copy link

@rodjsta I did follow your steps and changed code, disconnected apps, reconnected with new client_id and secret but did not work for me.

Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException: invalid_grant in C:\xampp\htdocs\myphp_version\vendor\league\oauth2-client\src\Provider\GenericProvider.php:222 Stack trace: #0 C:\xampp\htdocs\myphp_version\vendor\league\oauth2-client\src\Provider\AbstractProvider.php(628): League\OAuth2\Client\Provider\GenericProvider->checkResponse(Object(GuzzleHttp\Psr7\Response), Array) #1 C:\xampp\htdocs\myphp_version\vendor\league\oauth2-client\src\Provider\AbstractProvider.php(537): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request)) #2 C:\xampp\htdocs\myphp_version\authorizedResource.php(25): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\RefreshToken), Array) #3 {main} thrown in C:\xampp\htdocs\myphp_version\vendor\league\oauth2-client\src\Provider\GenericProvider.php on line 222

@roshanpokhrel1994
Copy link

Issue has been resolved. Seems the ID tokens of Xero have changed in format. So now with a base64 encoding the string became much longer and the storage column was not capable in storing the id length.

How did you resolve this issue ? i have same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants