Search code examples
javafirebasefirebase-authenticationfirebase-admin

Set up Firebase admin sdk with proxy (Java)


I'm trying to use firebase to authenticate my users via Google. On my Java server I'm verifying the validity of the idToken and every time I get this error:

com.google.firebase.auth.FirebaseAuthException: Error while verifying token signature.

I identified the problem as being the proxy of my server that avoid the http requests made by the sdk. I tested my code on my computer and it works so I'm pretty sure the problem is the proxy.

Here is my code:

InputStream serviceAccount = getClass().getClassLoader().getResourceAsStream(<fileName>);

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(<address>, <port>));
HttpTransport httpTransport = new NetHttpTransport.Builder().setProxy(proxy).build();

HttpTransportFactory httpTransportFactory = () -> httpTransport;

FirebaseOptions options = new FirebaseOptions.Builder()
   .setCredentials(GoogleCredentials.fromStream(serviceAccount, httpTransportFactory))
   .setDatabaseUrl(<adress>)
   .setHttpTransport(httpTransport)
   .build();
FirebaseApp.initializeApp(options);
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(<token>).get();

What am I doing wrong ?


Solution

  • I believe this is a bug. As you can see here, the token verifier does not use the HTTP transport injected through options. I'd appreciate if you can create an issue for this on GitHub.

    In the meantime, you might be able to get around this limitation by configuring the HTTP/S proxy for the JVM. Try setting the https.proxyHost and https.proxyPort system properties when starting the JVM (more details here).