Reputation: 436
i have created a laravel socialte setup .and it was working before perfectly now its showing error(below). 1)i have changed client_secret 2)created a new oauth credentials still not working
public function redirectToGoogle()
{
return Socialite::driver('google')->redirect();
}
public function handleGoogleCallback()
{
$user = Socialite::driver('google')->stateless()->user();
$user->getId(); // 1472352
$user->getNickname(); // "overtrue"
$name= $user->getName(); // "安正超"
$emailid= $user->getEmail();
$pic= $user->getAvatar(); // "[email protected]"
return->redirect('welcome');
}
i have created env file with client_secret and client id
"""
Client error: `POST https://accounts.google.com/o/oauth2/token` resulted in a `400 Bad Request` response:\n
{\n
"error" : "invalid_grant",\n
"error_description" : "Code was already redeemed."\n
}\n
"""
Upvotes: 2
Views: 14002
Reputation: 8069
When Google return the Authentication Code code
to your Socialite, it can only be used to exchange to Access Token once. Doing more than once will result in the error Code was already redeemed
.
The flow should be:
?code=.....
?code
and exchange it with Google to get user's Access Token. This can only be done once per flow.Read similar answer: https://stackoverflow.com/a/32710034/534862
Upvotes: 4