Popup blocking the gdrive authorization in chrome
Asked Answered
C

5

4

So, the problem is that popup blocking the window open even if it is done by a user action, click for example..

gapi.auth.authorize({
   client_id: this.client_id,
   scope: this.scopes,
   access_type: 'online',
   immediate: immediate
}, function(authResult) {
   console.log(authResult)
});

If i simply open the window on user click as here:

$('.some').click(funciton(){
    window.open(someurl)
})

it works fine, but if i did it throw the gdrive api(gapi.auth.authorize), this blocking anyway.

A must, I can not force users to off popap blocking. I hope that anybody now how solved it :), thanks

Conservationist answered 27/3, 2013 at 11:42 Comment(0)
I
5

Try this:

Include an onload event in your call to client.js

<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>

Call gapi.auth.init from the onload function:

function handleClientLoad() { window.setTimeout(gapi.auth.init,1); }

In your authorize configuration set immediate: false.

Check that 1. is below 2. in the flow of the page.

Inmesh answered 7/5, 2013 at 8:52 Comment(0)
R
4

Just adding the a reference https://developers.google.com/api-client-library/javascript/reference/referencedocs

gapi.auth.init(callback) Initializes the authorization feature. Call this when the client loads to prevent popup blockers from blocking the auth window on gapi.auth.authorize calls.

ps: vote up requires 15 reputation .. so couldn't vote up Ben's answer :)

Rhizocarpous answered 8/10, 2013 at 5:18 Comment(1)
Thank you so much!Kristelkristen
C
3

Popups that don't originate from user events will get blocked depending on your browser's settings. You can try setting immediate to false:

gapi.auth.authorize({
   client_id: this.client_id,
   scope: this.scopes,
   immediate: false
}, function(authResult) {
   console.log(authResult)
});

You can use this code to refresh the access token after you've already authorized the app.

Coreen answered 28/3, 2013 at 14:17 Comment(1)
In my example variable "immediate" already contains false, popap already pops but blocking. gapi.auth.authorize calls on click event, but anyway blocking, that's a problem.Conservationist
Y
0

The first call to gapi.auth.authorize can trigger popup blockers. The best way to prevent this is to set up a user-triggered action that calls gapi.auth.authorize with immediate: false parameter.

Quoted from the api documentation: https://developers.google.com/api-client-library/javascript/features/authentication#popup

Yalonda answered 20/1, 2016 at 14:59 Comment(0)
G
0

You only needs gapi.auth2.getAuthInstance().isSignedIn.get(); without button authorize permission. This disable the popup.

gapi.client.init({
     discoveryDocs: DISCOVERY_DOCS,
     clientId: CLIENT_ID,
     scope: SCOPES
}).then(function () {    
     // Handle the initial sign-in state.
     gapi.auth2.getAuthInstance().isSignedIn.get();
});
Gremial answered 2/11, 2017 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.