Make google auth request gapi.auth without a popup

余生颓废 提交于 2019-12-22 05:19:26

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/31293269/make-google-auth-request-gapi-auth-without-a-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!