Google authorized popup stuck in chrome extension

I am using the gapi client in the chrome extension to access Google Drive. The first step is to authorize my application. I use gapi.auth.authorize to start authorization. After I authorize the application through a pop-up window launched in gapi, the window never closes or gets stuck, as shown in the figure below. However, authorization succeeded in the background, because if I close the window manually, I don’t see a stuck popup next time. Can someone point out what I'm doing wrong?

After I click "Allow access" in the authorization pop-up window,

enter image description here

Then it shows an empty popup that is stuck

Popup gets stuck

The code I use

function handleClientLoad(){ gapi.client.setApiKey('My API key'); window.setTimeout(checkAuthAuto, 1); } var checkAuthAuto = function () { console.log('checkAuthAuto'); gapi.auth.authorize({ client_id: 'My client id', scope: 'https://www.googleapis.com/auth/drive.file', immediate: true }, handleAuthResult); } function handleAuthResult(authResult) { console.log('handleAuthResult'); var authButton = document.getElementById('authorizeButton'); var filePicker = document.getElementById('filePicker'); var addButton = document.getElementById('addButton'); authButton.style.display = 'none'; filePicker.style.display = 'none'; addButton.style.display = 'none'; if (authResult && !authResult.error) { addButton.style.display = 'block'; addButton.onclick = uploadFile; console.log('handleAuthResult:noerror'); } else { // No access token could be retrieved, show the button to start the authorization flow. authButton.style.display = 'block'; console.log('handleAuthResult:error'); console.log(authResult); authButton.onclick = function() { console.log('authButton.onclick'); gapi.client.setApiKey('My api key'); gapi.auth.authorize({ client_id: 'My client id', scope: 'https://www.googleapis.com/auth/drive.file', immediate: false }, handleAuthResult); return false; }; } } 
+6
source share
1 answer

Even with chrome extensions, you can use chrome.identity, and the popup closes the same way we expect.

Wrap the chrome .identity.getAuthToken with a wrapper named gapi.auth.authorize. Refer to: https://github.com/GoogleChrome/chrome-app-samples/blob/master/gapi-chrome-apps-lib/gapi-chrome-apps.js

The fact is that the current stable chrome 28 does not allow you to do this, and you can check the version or wait a while until the stable one receives this functionality. Still not sure though, doing this with extensions is good, even if I could do it ...

0
source

All Articles