admin管理员组

文章数量:1323348

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 badges
Add a ment  | 

1 Answer 1

Reset to default 10 +200

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!

本文标签: javascriptGoogleUser object does not have grantOfflineAccess methodStack Overflow