Firefox登录谷歌登录 [英] Firefox plugin with google signin

查看:203
本文介绍了Firefox登录谷歌登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Firefox插件,并试图将Google Signin功能添加到插件中。 (我之前成功将此功能添加到Chrome插件)。
我遵循本文中的说明( https://developers.google .COM /身份证/登录/网络/接收器)。但登录弹出不显示,没有用户对象正在创建,以下是我的代码



  var googlePlusUserLoader =(function(){var login_btn; var login_dev; var main_dev; var uname_lbl; var logout_btn; var auth2; var googleUser; function showLoginScreen(){login_dev.style.display ='block'; main_dev.style.display ='none';} function showMainScreen(){login_dev函数populateUserInfo(user_info);函数populateUserInfo(user_info);函数populateUserInfo(user_info);函数populateUserInfo(user_info ){uname_lbl.innerHTML = user_info.displayName;}函数refreshValues(){if(auth2){console.log('Refreshing values ...'); goog leUser = auth2.currentUser.get(); }}函数initAuthObject(){gapi.load('auth2',function(){auth2 = gapi.auth2.init({client_id:'xxxx.apps.googleusercontent.com',scope:'https://www.googleapis .com / auth / plus.me https://www.googleapis.com/auth/drive profile email',cookie_policy:'none'}); auth2.isSignedIn.listen(function(){console.log('signin states改变');}); auth2.currentUser.listen(function(){console.log('user changed');}); auth2.signIn()。then(function(user){console.log(JSON.stringify (user));});}); } return {onload:function(){login_btn = document.getElementById('signinBtn'); login_dev = document.getElementById('divLogin'); main_dev = document.getElementById('divMain'); uname_lbl = document.getElementById('username'); logout_btn = document.getElementById('logoutBtn'); showLoginScreen(); initAuthObject(); }};})(); window.onload = googlePlusUserLoader.onload;  

b
$ b

console.log(JSON.stringify(user));

这行不会记录任何东西在控制台中



您只需要打开一个标签到这个URL:

  gBrowser.loadOneTab('https://accounts.google.com/o/oauth2/auth?'+ jQLike.serialize({ 
client_id:'your client id',
redirect_uri:'your redir uri',
scope:['https://www.googleapis.com/auth/plus.me',' (''),
response_type:'token'
})


// rev1 - https://gist.github.com/Noitidart/6c172e77fe48f78521f2
var jQLike = {//我的独立jQuery像函数
serialize:function(aSerializeObject){
var serializedStrArr = [];
(aSerializeObject中的var cSerializeKey){
serializedStrArr.push(encodeURIComponent(cSerializeKey)+'='+ encodeURIComponent(aSerializeObject [cSerializeKey]));
}
return serializedStrArr.join('&');
}
};

然后使用 page-mod 您的重定向URI - https://developer.mozilla .org / en-US / Add-ons / SDK / High-Level_APIs / page-mod


I'm developing a Firefox plugin and trying to add Google Signin feature to the plugin. ( I successfully added this feature to a Chrome plugin before). I followed the instructions in this article ( https://developers.google.com/identity/sign-in/web/listeners). But the signin popup is not showing and no user object is creating, following is my code

var googlePlusUserLoader = (function() {

    var login_btn ;
    var login_dev ;
    var main_dev ;
    var uname_lbl;
    var logout_btn;

    var auth2;
    var googleUser;

    function showLoginScreen(){
        login_dev.style.display = 'block';
        main_dev.style.display = 'none';
    }

    function showMainScreen(){
        login_dev.style.display = 'none';
        main_dev.style.display = 'block';
    }

    function hideAll(){
        login_dev.style.display = 'none';
        main_dev.style.display = 'none';
    }

    function populateUserInfo(user_info) {
        uname_lbl.innerHTML = user_info.displayName;
    }

    function refreshValues(){
        if (auth2){
            console.log('Refreshing values...');
            googleUser = auth2.currentUser.get();
        }

    }

    function initAuthObject(){
        gapi.load('auth2',function(){
          auth2 =   gapi.auth2.init({
                client_id: 'xxxx.apps.googleusercontent.com',
                scope: 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/drive profile email',
                cookie_policy: 'none'
            });

            auth2.isSignedIn.listen(function () {
                console.log('signin states changed');
            });

            auth2.currentUser.listen(function(){
                console.log('user changed');
            });

            auth2.signIn().then(function(user) {
                console.log(JSON.stringify(user));
            });

        });

    }

    return {
        onload: function () {

            login_btn = document.getElementById('signinBtn');
            login_dev = document.getElementById('divLogin');
            main_dev = document.getElementById('divMain');
            uname_lbl = document.getElementById('username');
            logout_btn = document.getElementById('logoutBtn');

            showLoginScreen();
            initAuthObject();
        }
    };

})();

window.onload = googlePlusUserLoader.onload;

console.log(JSON.stringify(user));

this line doesn't log anything in the console

解决方案

That's a lot of complicated stuff.

You simply need to open a tab to this url:

gBrowser.loadOneTab('https://accounts.google.com/o/oauth2/auth?' + jQLike.serialize({
        client_id: 'your client id',
        redirect_uri: 'your redir uri',
        scope: ['https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/drive'].join(' '),
        response_type: 'token'
    })
)

// rev1 - https://gist.github.com/Noitidart/6c172e77fe48f78521f2
var jQLike = { // my stand alone jquery like functions
    serialize: function(aSerializeObject) {
        var serializedStrArr = [];
        for (var cSerializeKey in aSerializeObject) {
            serializedStrArr.push(encodeURIComponent(cSerializeKey) + '=' + encodeURIComponent(aSerializeObject[cSerializeKey]));
        }
        return serializedStrArr.join('&');
    }
};

Then just use a page-mod on your redirect URI - https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-mod

这篇关于Firefox登录谷歌登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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