Laravel socialite 400 Bad请求回复 [英] Laravel socialite 400 Bad Request response

查看:358
本文介绍了Laravel socialite 400 Bad请求回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个laravel socialte设置.它在完美显示之前就可以正常工作了(如下). 1)我更改了client_secret 2)创建一个新的oauth凭证 仍然不起作用

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');

}

我已经创建了带有client_secret和客户端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
    """

推荐答案

Google将身份验证代码 code返回给您的社交名流时,它只能用于交换访问令牌.重复执行多次将导致错误Code was already redeemed.

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.

流应为:

  1. 用户单击您网站上的登录按钮
  2. 您将用户重定向到Google,而Google要求用户登录/授予您访问权限
  3. 如果成功,则Google会使用一次性身份验证代码 ?code=.....
  4. 重定向回您
  5. 社交名流使用?code并将其与Google交换以获得用户的访问令牌.每个流只能执行一次.
  6. 您现在可以使用第4步中请求的访问令牌来请求用户详细信息.
  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.

阅读类似的答案: https://stackoverflow.com/a/32710034/534862

这篇关于Laravel socialite 400 Bad请求回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆