Laravel socialite 400 Bad Request response

*爱你&永不变心* 提交于 2020-01-04 05:46:17

问题


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();    // "anzhengchao@gmail.com"
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
    """

回答1:


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:

  1. User click the login button on your website
  2. You redirect user to Google and Google is asking user to login/grant you access
  3. If successful, Google redirects back to you with a one-time-use Authentication Code?code=.....
  4. Socialite use the ?code and exchange it with Google to get user's Access Token. This can only be done once per flow.
  5. You can now request user details using the access token requested in step 4.

Read similar answer: https://stackoverflow.com/a/32710034/534862



来源:https://stackoverflow.com/questions/48616799/laravel-socialite-400-bad-request-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!