简体   繁体   中英

Firebase authentication doesn't work on Java(jvm) (Desktop)

I am building a desktop software(Java) that connects to Firebase.

I can create an user perfectly using the software (it is shown on Firebase Project User Page exactly as created), but when I try to authenticate this user (using the same software), I get an error from the server.

No matter how I try to log in (I am using Firebase.authWithPassword and Firebase.authWithCustomToken), but both don't work.

I've seen loads of videos and tutorials examples using Web or Android (so easy to do) but none using Java jvm, not even in Firebase Docs (they do have Android and Web examples but none in Java), so I am not sure if I am doing it right. I am following the documentation, but it is not working.

Any Ideas?

String customToken =     FirebaseAuth.getInstance().createCustomToken(uid);
System.out.println("CUSTOM TOKEN >> " + customToken);

Firebase firebase = new Firebase(projectURL);

//firebase.authWithCustomToken(customToken, authResultHandler);
firebase.authWithPassword(userMail, userPass, authResultHandler);

Using CustomToken (firebase.authWithCustomToken(customToken, authResultHandler)) I get this error (I am using a Custom Token created with the UID given when the user was created (using FirebaseAuth.getInstance().createCustomToken(uid))

AUTH ERROR -> FirebaseError: Expected an ID token, but was given a custom token.

AUTH ERROR -> -7

Using Email/Password auth (firebase.authWithPassword(userMail, userPass, authResultHandler), I get this error:

AUTH ERROR -> FirebaseError: Error while authenticating.

AUTH ERROR -> -999

[PS. The Email/Pass login is enable in Firebase authentication page]

I think I figured it out what is happening.

I am using Java (jvm) to build this desktop interface, for creating users and login them too.

the lib I am using is firebase-admin-6.7.0.jar.

I noticed that in other libs (for android, js, for example), the method to authenticate the user is in FIREBASE.AUTH (or similar)...

In Java(jvm) lib, there is a class FIREBASEAUTH (which is very similar in methods to the FIREBASE.AUTH in other libs) but there is no such methods like SIGNINWITHCUSTOMTOKEN or SIGNINWITHEMAIL in it (as in firebase.auth in other languages libs)

The class FirebaseAuth (jvm) does have the method to create users, but no method to authenticate them (like similar libs in other languages)

The only method I found to authenticate users is in the class FIREBASE , which has methods like Firebase.createUser and the sign in methods like Firebase.authWithCustomToken , Firebase.authWithPassword , firebase.authAnonimously and others (they are not in FirebaseAuth class)...

So, to create an user, there are two classes with the same method, Firebase.createUser (wich doesn't work) and FirebaseAuth.createUser (wich works perfectly).

I believe there is a bug in the jvm lib, the methods to authenticate users don't exist in the class FirebaseAuth , instead, they are in Firebase class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM