在没有弹出窗口的情况下使谷歌验证请求gapi.auth [英] Make google auth request gapi.auth without a popup

查看:130
本文介绍了在没有弹出窗口的情况下使谷歌验证请求gapi.auth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要在js中创建身份验证请求,但浏览器不支持弹出窗口。有什么方法可以重定向到一个新的url或者在应用程序的html5页面显示请求 使用这个 代码检查用户是否授权您的应用程序

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

注意:立即:true
如果你设置的是立即的,那么它不会显示弹出。



你看到了吗?你不打开弹出窗口,并在回调中管理这些东西。回调通常用于后处理。这里我们用它进行验证。



callbackAuthResult

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

//在这里处理你的数据

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



callbackAuthClick = function(event){
gapi.auth.authorize({
client_id:clientId,
scope:范围
immediate:false
},handleAuthResult);
返回false;
}


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

解决方案

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

这篇关于在没有弹出窗口的情况下使谷歌验证请求gapi.auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆