Firestore / gRPC behind a corporate firewall / proxy

懵懂的女人 提交于 2019-12-05 04:26:58

As can be seen in the source code, the node.js client library accesses Firestore through gRPC at firestore.googleapis.com on port 443.

So for your application to work with Firestore successfully, the firewall/proxy must allow access to firestore.googleapis.com on port 443 via TCP. Why this doesn't work at the moment is a question to the current configuration of the firewall/proxy, most probably it is blocked by default in some catch-all rule.

Warning: GRPC currently only supports HTTP Basic Auth for proxies. The proxy authentication method here will currently not work, if the proxy requires authentication via Digest. I have filed an issue for it here: https://github.com/grpc/grpc/issues/18250


The solution is to set the environment variables for http_proxy and https_proxy before loading the Electron BrowserWindow that initiates the Firestore connection.

An possible way is to ask for proxy credentials in the BrowserWindow and return them to the main process using an event (in this example set-proxy-url). After setting the environment variables correctly for gRPC to pick them up, reload the BrowserWindow (or open a new one).

Example code (main):

ipcMain.on('set-proxy-url', (event: Electron.Event, arg: any) => {
  if (arg.authInfo.isProxy) {
    // In our case this is a http proxy (HTTPS is tunneled)
    const httpUrl = `http://${arg.user}:${arg.pass}@${arg.authInfo.host}:${arg.authInfo.port}`

    process.env.http_proxy = httpUrl
    process.env.https_proxy = httpUrl

    // TODO: Reload the BrowserWindow that uses Firestore
  }
})

Example code (renderer):

ipcRenderer.send('set-proxy-url', {
     authInfo, // This comes from app.on('login', (event, webContents, request, authInfo, callback) => { ... }
     user: usernameRetrievedFromUser,
     pass: passwordRetrievedFromUser
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!