-->

chrome.identity not showing all the logged in goog

2019-09-14 11:26发布

问题:

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.