thephpleague / oauth2-client

Easy integration with OAuth 2.0 service providers.

Home Page:http://oauth2-client.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

invalid_grant exception in /league/oauth2-google

githubRover opened this issue · comments

I used the league OAuth2 successfully a few times from PHPMailer with gmail. But, sometime later (days, maybe a week) my app started to receive the below error. I am baffled - not even sure where to start debug - any help appreciated. I did not recreate the refresh token or change anything else in my google developer client ID. My PHP mailer code looks very similar to what was reported a long time ago in issue #809. My error also was un-caught until I resolved that (see below) so I could obtain the entire stack trace shown here.

League\OAuth2\Client\Provider\Exception\IdentityProviderException: invalid_grant in /var/app/current/vendor/league/oauth2-google/src/Provider/Google.php:120
Stack trace:
#0 /var/app/current/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(628): League\OAuth2\Client\Provider\Google->checkResponse(Object(GuzzleHttp\Psr7\Response), Array)
#1 /var/app/current/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(537): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request))
#2 /var/app/current/vendor/phpmailer/phpmailer/src/OAuth.php(115): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\RefreshToken), Array)
#3 /var/app/current/vendor/phpmailer/phpmailer/src/OAuth.php(128): PHPMailer\PHPMailer\OAuth->getToken()
#4 /var/app/current/vendor/phpmailer/phpmailer/src/SMTP.php(583): PHPMailer\PHPMailer\OAuth->getOauth64()
#5 /var/app/current/vendor/phpmailer/phpmailer/src/PHPMailer.php(2073): PHPMailer\PHPMailer\SMTP->authenticate('', '', 'XOAUTH2', Object(PHPMailer\PHPMailer\OAuth))
#6 /var/app/current/vendor/phpmailer/phpmailer/src/PHPMailer.php(1887): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array)
#7 /var/app/current/vendor/phpmailer/phpmailer/src/PHPMailer.php(1609): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Fri, 19 M...', 'CheckLog News R...')
#8 /var/app/current/vendor/phpmailer/phpmailer/src/PHPMailer.php(1442): PHPMailer\PHPMailer\PHPMailer->postSend()
#9 /var/app/current/(my calling app).php(167): PHPMailer\PHPMailer\PHPMailer->send()
(... remainder of stack trace omitted - just my calling chain above PHPMailer ...)

I was able to catch the error by changing the line shown in issue #809 :
catch (IdentityProviderException $e)
with just:
catch (Exception $e)

Thanks

Please submit this issue to the oauth2-google repository. Thanks! https://github.com/thephpleague/oauth2-google