Google oauth2 with google plus:使用后端服务器进行身份验证

时间:2017-08-18 16:33:14

标签: javascript django oauth-2.0 python-social-auth

我使用以下教程使用Javascript在客户端登录用户: https://developers.google.com/+/web/people/

网页上给出的代码工作正常,但我想获取登录用户的access_token,以便我可以将其发送到我的Django后端来验证用户。 我可以通过使用Google Chrome浏览器监控网络请求来获取访问令牌,但我不明白如何以编程方式获取令牌。

我看过这篇文章,但没有帮助: https://developers.google.com/identity/sign-in/web/backend-auth

如果我使用这段代码:

function onSignIn(googleUser) {
  var id_token = googleUser.getAuthResponse().id_token;
  ...
}

使用第一个链接上的代码,它不会被调用。 任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

以下是解决方案的要点:

  

https://gist.github.com/nikssardana/4739f700961cbcf2d2e31afdcfa8a143

经过这么多尝试,我意识到我发送的是id_token而不是access_tokenGoogle documentation表示我们应该使用后端发送id_token身份验证,但出于某种原因social_django接受access_token

相关问题