chrome.identity not showing all the logged in google account on popup

烈酒焚心 提交于 2019-12-11 16:44:11

问题


I am building an chrome extension in which I used

chrome.identity.getAuthToken({
        interactive: true
    }, function(token) {
        if (chrome.runtime.lastError) {
            alert(chrome.runtime.lastError.message);
            return;
        }
        var x = new XMLHttpRequest();
        x.open('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + token);
        x.onload = function() {
            alert(x.response);
        };
        x.send();
    });

on background.js for google login authentication.

When this function called, a window appear which show logged-in google accounts (if any) but my problem is it shows only 1 account but I logged-in 5 accounts in the browser.

Is there anything which I missed over here ?

And I also need to know how to write logout function ?


回答1:


chrome.identity will use the account that is "signed in" in chrome://settings. If not signed into Chrome, it will pop up a tab to allow you to "sign in" to Chrome, meaning linking the current profile and a google account.

If you want to show all the accounts simply signed in, you will need to manually create a popup window (using e.g. chrome.tabs.create or window.open and have the redirect url go back to your server which then communicates to your extension (e.g. using sendMessage and onMessageExternal), or if you have tabs permission, you could redirect using urn:ietf:wg:oauth:2.0:oob:auto as your redirect url, which will make the oauth grant appear in the window.title, which you can read with your tabs permission.



来源:https://stackoverflow.com/questions/44691365/chrome-identity-not-showing-all-the-logged-in-google-account-on-popup

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