Can I choose user before get chrome identity token? [duplicate]

女生的网名这么多〃 提交于 2019-12-12 14:47:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!