I want to connect from a browser to Google Drive by OAuth2 with two scopes:
https://www.googleapis.com/auth/drive- necessaryhttps://www.googleapis.com/auth/drive.install- optional.
When I use both scopes in google.accounts.oauth2.initTokenClient and a user confirms just the necessary scope and reloads the page (or token expires), then the user is bothered with a window to confirm the optional scope. So, I have tried to do two calls: the first one with no prompt and necessary scope only, if it fails, then the second one with both scopes:
let tokenResponse = await new Promise(resolve => {
google.accounts.oauth2.initTokenClient({
client_id: clientId,
scope: scope1,
prompt: "none", // never show a popup
callback: resolve
}).requestAccessToken();
});
if (tokenResponse.error && tokenResponse.error === "interaction_required") {
tokenResponse = await new Promise(resolve => {
google.accounts.oauth2.initTokenClient({
client_id: clientId,
scope: scope1 + " " + scope2,
prompt: undefined, // show popup
callback: resolve
}).requestAccessToken();
});
}
However, the second call never returns (even when I have pop-ups explicitly allowed). How is possible to handle optional scopes or two calls to requestAccessToken()?