GoogleUser对象没有grantOfflineAccess方法? [英] GoogleUser object does not have grantOfflineAccess method?

查看:187
本文介绍了GoogleUser对象没有grantOfflineAccess方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Google登录在我的网站上对用户进行身份验证,然后将其作为根据文档,GoogleUser对象应该有一个grantOfflineAccess方法,该方法会提示您输入额外的权限,而不是。提示用户确认他们的账户。然而,检查Firebug中的对象,我发现所有其他方法描述,但不是grantOfflineAccess。

我有一个解决方法使用GoogleAuth对象的grantOfflineAccess方法,但强制用户确认他们的帐户(我想避免,因为他们 在登录过程中执行了该步骤)。我想保持登录和授权离线访问提示分开,所以我可以做他们之间的一些验证。



文档是否错误/过时?有没有另一种方法来获得我想要的行为?

解决方案

我自己查了一下,这个方法真的不存在。我认为这实际上是文档中的错误。



因此,我探索了一下,找到了另一种方法来实现你想要的:有一个(显然没有记录的)名为 authuser 的参数。它基本上是您登录帐户的索引(第一个为0,第二个为1,...)。 Google在内部使用GoogleDocs等内容。经过一番更多的处理后,我在GoogleUser数据中找到了authuser:

$ b



原来, wc getAuthResponse()数据,因此您可以通过以下方式访问此索引: gapi.auth2.getAuthInstance()。currentUser.get()。getAuthResponse()。session_state.extraQueryParams.authuser p>

您现在可以使用此参数调用 GoogleAuth grantOfflineAccess ,导致以下调用:

  var auth = gapi.auth2.getAuthInstance(); 
var user = auth.currentUser.get();
auth.grantOfflineAccess({
authuser:user.getAuthResponse()。session_state.extraQueryParams.authuser
});

这会在没有帐户选择器的情况下打开提示:-)希望我可以帮忙!


I am using Google Sign-in to authenticate users on my website and then as a separate step asking for offline permissions.

According to the documentation, the GoogleUser object should have a method "grantOfflineAccess" which prompts for additional permissions without prompting the user to confirm their account. However inspecting the object in Firebug, I find all the other methods described but not grantOfflineAccess.

I have a workaround using the GoogleAuth object's grantOfflineAccess method but that forces the user to confirm their account (which I would like to avoid, as they have just performed that step during login). I would like to keep the login and authorize offline access prompts separate so I can do some validation between them.

Is the documentation wrong/outdated? Is there another way to get my desired behaviour?

解决方案

I just checked it out myself, the method really doesn't exist. I think this is actually an error in the docs.

So I poked around a little bit and found another way to achieve what you want: There is an (apparently undocumented) parameter named authuser. It's basically the index of the account you are logged in (0 for the first, 1 for the second, ...). Google uses this internally for stuff like GoogleDocs etc. After some more poking, I found the authuser in the GoogleUser data:

Turns out that wc is the getAuthResponse() data, so you can access this index with: gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().session_state.extraQueryParams.authuser.

You can now call the grantOfflineAccess of GoogleAuth with this parameter, resulting in the following call:

var auth = gapi.auth2.getAuthInstance();
var user = auth.currentUser.get();
auth.grantOfflineAccess({
  authuser: user.getAuthResponse().session_state.extraQueryParams.authuser
});

This will open the prompt without an account chooser :-) Hope I could help!

这篇关于GoogleUser对象没有grantOfflineAccess方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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