Firebase身份验证在代理后面失败

时间:2016-10-19 09:40:05

标签: javascript node.js firebase proxy firebase-authentication

我有一台Express服务器正在推送Firebase数据库上的一些数据。 此服务器托管在Intranet上,因此位于代理服务器后面。我设置了HTTP_PROXYHTTPS_PROXY环境变量,因此可以连接到Internet。

不要使用Express服务器,只需考虑一个基本的nodeJs代码段。

当我尝试读取数据时,它可以正常工作(Firebase数据库配置为允许任何人(包括匿名用户)读取权限):

const firebase = require('firebase');
function test() {
  firebase.initializeApp({
    apiKey: 'xxx',
    authDomain: 'xxx.firebaseapp.com',
    databaseURL: 'https://xxx.firebaseio.com',
    storageBucket: ''
  });
  firebase.auth().onAuthStateChanged(currentUser => {
    console.log('USER IS => ', currentUser);
  });
  firebase.database().ref('configuration').once('value', data => {
    console.log('GOT: ', data.val());
  });
}
test();

此代码的输出为:

USER IS => null  // OK, since I didn't authenticate
GOT: { 'foo': 'bar' }     // I got correct data from the database

现在,我在请求数据之前添加了身份验证机制:

const firebase = require('firebase');
function test() {
  firebase.initializeApp({...});
  firebase.auth().signInAnonymously().catch(err => {
    console.log('ERROR !', err);
  });
  firebase.auth().onAuthStateChanged(currentUser => {
    console.log('USER IS => ', currentUser);
  });
  firebase.database().ref('configuration').once('value', data => {
    console.log('GOT: ', data.val());
  });
}
test();

输出结果为:

USER IS => null
ERROR ! { [Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred.]
  code: 'auth/network-request-failed',
  message: 'A network error (such as timeout, interrupted connection or unreachable host) has occurred.' }
GOT: { 'foo': 'bar' }

电子邮件/密码验证(firebase.auth().signInWithEmailAndPassword('a@example.com', 'foobar'))也是如此。

从我所看到的,节点代码能够到达firebase(因为我可以检索数据),但是身份验证无法实现。

我还尝试使用firebase.js库将该代码放在HTML页面中。在这种情况下,我没有问题进行身份验证(这意味着我的企业代理不会阻止某些身份验证URL,例如googleapis.com)。

我在这里缺少什么?

感谢。

0 个答案:

没有答案