且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel socialite 400 Bad请求回复

更新时间:2023-01-03 18:46:48

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://***.com/a/32710034/534862