问题
I'm working on Chrome extension which work on Gmail, and for login by google account, I use chrome.identity.getAuthToken to get auth_token
chrome.identity.getAuthToken({'interactive': false},
googlePlusLoginCallback)
it works fine while user only has one gmail account.
But in the scenario user has more gmail accounts(like private one and one from company), the api only use the primary account to request auth_token; Is it possible to let user choose their account before request auth_token?
回答1:
Like abraham said, chrome.identity uses the Chrome browser profile, so a multi-account user would have to have different browser profiles for each account.
Unfortunately, it seems the only way to handle multiple Google accounts (but not multiple Chrome profiles) is to keep track of each user in the background and switch the active user whenever you get an indication that the user has changed.
A solution is to store each user in the background via localStorage along with their access_token, and indicate which is the active user. You can listen to ajax calls that are made to-from Google via chrome.webRequest.onBeforeRequest, as some of those ajax calls will contain the current Google user.
来源:https://stackoverflow.com/questions/31969398/can-i-choose-user-before-get-chrome-identity-token