Firebase Cloud Messaging (FCM) notifications doesn't work on devices behind proxy. Is there any alternative way to solve it?

Viewed 4922

Our Android application is working over 2000 devices on field. This is a corporate app, not published on Google Play and we are managing our operations via these devices. Most important point for us: All of our client Android devices are behind proxy. (We have already take all actions on Firebase document warning about "If your organization has a firewall...")

We are testing to adapt FCM to our app for receiving notifications. We are using HTTP Protocol, sending Post requests to https://fcm.googleapis.com/fcm/send URL address, so our choice is Downstream HTTP Messages (JSON) and we are sending data messages both via Postman and also via our .Net desktop app. Firebase Cloud Messaging notifications are working successfully when device is connected to Internet via independent WiFi. It is also working successfully when device is connected to Internet via mobile network operator SIM card (No Proxy). But these methods are not a solution for us, because all of our devices are working behind proxy.

Is Firebase Cloud Messaging notifications not working on devices behind proxy? I found some bad news about FCM and behind proxy devices, but I am not sure. We want to use FCM notifications, however 3rd party extra apps is not a good solution for us. Because we are managing too many devices on field and we have also security issues. Is there any alternative solution to solve this issue about proxy?

3 Answers

Please note that as of 2019 Firebase has some Proxy Support, at least using Java or Node.js, see this Article about it: https://medium.com/faun/firebase-accessing-firestore-and-firebase-through-a-proxy-server-c6c6029cddb1

In case the Link is down, this is an example for Java configuration, all credits go to Hiranya Jayathilaka who wrote this great Tutorial (many thanks!)

String myProxyHost = "localhost"; // REPLACE
int myProxyPort = 3128; // REPLACE

InetSocketAddress address = new InetSocketAddress(myProxyHost, myProxyPort);
HttpTransport transport = new NetHttpTransport.Builder()
        .setProxy(new Proxy(Proxy.Type.HTTP, address))
        .build();

FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
builder.setHttpTransport(transport);
// ... further configuration ...

Addition:

I have tried this solution and setting the HttpTransport only proxies requests to "fcm.googleapis.com", which is not sufficient in my case, because the Firebase Sdk first retrieves an Authorization Token from "accounts.google.com".

To Proxy requests to "accounts.google.com" also, I had to use System-Properties like this:

System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", String.valueOf(proxyPort));            
System.setProperty("com.google.api.client.should_use_proxy", "true");
Related