Google登录网站 - 如何获取令牌

时间:2017-06-27 04:19:12

标签: javascript html authentication google-authentication google-oauth2

我正在使用Google登录网站。 https://developers.google.com/identity/sign-in/web/

根据文档,在Yii::t()函数下,我使用onSignIn(googleUser)

获取ID_Token

但显然这不是我将来可以使用的googleUser.getAuthResponse().id_token撤销。如何从googleUser对象获取客户端的access_token

2 个答案:

答案 0 :(得分:4)

经过几个小时的破解,我得到了Google开发人员的回答。

使用以下行。在true函数中传递getAuthResponse会返回access_tokenexpiry。这是推荐的解决方案。

googleUser.getAuthResponse(true).access_token;

答案 1 :(得分:2)

检查回叫中的googleUser。你会发现Zi属性。在该对象中,您还会发现access_tokenexpire次。

function onSignIn(googleUser) {
    console.log(googleUser.Zi);
}