Jignesh Aakoliya
Jignesh Aakoliya

Reputation: 43

Google SSO aouth 2.0 gives Error fetching OAuth2 access token, message: 'invalid_grant: Code was already redeemed.'

I have sign in with google enable in my website it is working fine since last 3-4 month but from yesterday it start giving me following error on every 4-5 minuites

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant: Code was already redeemed.'' in F:\ServerFolders\Projects\domain.com\src\Google\Client.php(131): Google_Auth_OAuth2->authenticate('4/8hj0saqecCytQ...', false) #1 F:\ServerFolders\Projects\domain.com\application\libraries\NV_gmail.php(105): Google_Client->authenticate('4/8hj0saqecCytQ...') #2 F:\ServerFolders\Projects\domain.com\application\libraries\layout.php(51): NV_gmail->login() #3 F:\ServerFolders\Projects\tl-l.com\application\controllers\dashboard.php(19): layout->header() #4 [internal function]: dashboard->index() #5 F:\ServerFolders\Projects\domain.com\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #6 F:\ServerFolders\Projects\domain.com\index.php(202): require_once('F:\ServerFolder...') #7 {main} thrown in F:\ServerFolders\Projects\domain.com\src\Google\Auth\OAuth2.php on line 126

And shows blank page .

Upvotes: 1

Views: 727

Answers (2)

Jignesh Aakoliya
Jignesh Aakoliya

Reputation: 43

Change

curl_setopt($curl, CURLOPT_SSLVERSION, 3); 

to

 //curl_setopt($curl, CURLOPT_SSLVERSION, 3); 

from curl.php according to github.com/google/google-api-php-client/issues/639 and now working fine

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117271

When the user clicks authenticate you are given an authentication code. You take this code and exchange it for your access token and refresh token.

'invalid_grant: Code was already redeemed

Means that you are taking an authentication code that has already been used and trying to get another access token / refresh token for it.

If it has worked for the last 4 months my opinion is that someone changed something in your code and broke it.

Upvotes: 1

Related Questions