Make a google auth gapi.auth request without a popup

You need to make an auth request in js, but the browser does not support pop-ups. Is there a way to redirect to a new url or show a request on the html5 page of the application

+4
source share
1 answer

Using this code, check if your application is allowed to the user.

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

Note: immediate:true if you set the immediate value to true, then it will not display a popup.

You see? You do not open the pop-up window and do not control the material in the callback. This callback is commonly used for post processes. Here we use it for authentication.

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;
}
+1

All Articles