admin管理员组文章数量:1323524
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 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?
Share Improve this question edited Sep 29, 2015 at 19:55 Wogan asked Sep 29, 2015 at 16:09 WoganWogan 72.7k5 gold badges36 silver badges36 bronze badges1 Answer
Reset to default 10 +200I 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!
本文标签: javascriptGoogleUser object does not have grantOfflineAccess methodStack Overflow
版权声明:本文标题:javascript - GoogleUser object does not have grantOfflineAccess method? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742131893a2422199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论