Pregunta

I have server written in Java, the server is writing to my firebase and I would like to add authentication to ensure that it is only my server that can perform these updates.

I have included the firebase-simple-login-LATEST.jar in my class path and altered by code to attempt to authenticate based on a user/password combination see below

Firebase fb = new Firebase("https://myfirebase.firebaseio.com");
SimpleLogin sl = new SimpleLogin(fb);
sl.loginWithEmail("user@email.address", "password", new SimpleLoginAuthenticatedHandler() {
  @Override
  public void authenticated(Error error, User user) {
    if (error == null) {
       // Do some work here
    }
  }
});

My problem is that even though my server is pure java and not running any aspects of android, I get run time errors complaining that

java.lang.ClassNotFoundException: android.net.Uri

I presume there is some internal dependency in the simple login java code. I am wondering if there is a pure Java (with no android dependency) jar file that I can use as I do not really want to have to include a load of android jars in my build

¿Fue útil?

Solución

The simple login jar depends on the Android runtime, but if you just want to authenticate a server, you can do one of two things:

  1. Use your Firebase secret as the auth credential

  2. Generate a specific admin token for your server

See the documentation here: https://www.firebase.com/docs/security/custom-login.html

Helper libraries are available in several languages for generating your own token.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top