Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make google auth request gapi.auth without a popup

Need to make auth request in js but the browser does not support popups. Is there any way to redirect to a new url or show the request in the in html5 page of the application

like image 753
250 Avatar asked Jul 08 '15 12:07

250


1 Answers

By using this code check if user authorized your app

gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, callbackAuthResult);

Note: immediate:true if you set immediate true then it wont show popup.

You see? You don't open the popup, and manage the stuff in the callback. This callback is usually used for post-processes. Here we use it for authenticating.

in callbackAuthResult:

callbackAuthResult = function (authResult) {
    var authorizeButton = document.getElementById('authorize-button');
    if (authResult && !authResult.error) {
        authorizeButton.style.display = 'none';

    // do your processing here

    } else {
    authorizeButton.style.display = 'block';
    authorizeButton.onclick = callbackAuthClick;
    }
}

callbackAuthClick = function (event) {
gapi.auth.authorize({
    client_id: clientId,
    scope: scopes,
    immediate: false
}, handleAuthResult);
    return false;
}
like image 82
3pic Avatar answered Oct 04 '22 21:10

3pic