I found a way, but a little sad that this function is not included (or not documented) in gapi.auth.authorize .
In any case, if you open the authorization pop-up window manually and then process the received token, you can pass additional parameters, such as prompt=select_account , which will allow the user to select their account.
Here is a sample code. When blocking pop-ups, you will need to call this function in the onclick event so that the pop-up does not block.
Therefore, the code is not ready for production. We do not manage cases, for example, when a user refuses to give his consent, and we do not transmit additional information about tokens, such as the expiration time.
var switchUserAccount = function (callback) { var popup = window.open("https://accounts.google.com/o/oauth2/auth?client_id=102862643449-geb89aoann7dj6tsha4mtkhvos5mk01b.apps.googleusercontent.com" + "&prompt=select_account" + "&scope=https://www.googleapis.com/auth/userinfo.email" + "&redirect_uri=https://david-sandbox.appspot.com/autoclose.html" + "&access_type=online&response_type=token", "thewindow"); var waitForPopup = function () { try { var token = popup.location.hash.substring(14).split("&")[0]; console.log("FOund token !" + token); if (token == "") { console.log("Not ready yet") setTimeout(waitForPopup, 500); } else { gapi.auth.setToken({access_token: token}); popup.close(); callback(); } } catch (e) { console.log("Not ready yet, exception") setTimeout(waitForPopup, 500); } }; waitForPopup(); }
source share