简体   繁体   English

Firebase身份验证不适用于Java(jvm)(桌面)

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

I am building a desktop software(Java) that connects to Firebase. 我正在构建连接到Firebase的桌面软件(Java)。

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. 我可以使用该软件完美地创建用户(它在Firebase Project用户页面上完全按照创建的方式显示),但是当我尝试对该用户进行身份验证(使用相同的软件)时,我从服务器收到错误消息。

No matter how I try to log in (I am using Firebase.authWithPassword and Firebase.authWithCustomToken), but both don't work. 无论我如何尝试登录(我正在使用Firebase.authWithPassword和Firebase.authWithCustomToken),但两者均无法正常工作。

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. 我看过很多使用Web或Android的视频和教程示例(很容易做到),但是没有使用Java jvm的视频和教程示例,甚至在Firebase Docs中也没有(他们有Android和Web示例,但在Java中没有),所以我不确定如果我做对了。 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)) 使用CustomToken(firebase.authWithCustomToken(customToken,authResultHandler))我收到此错误(我使用的是使用创建用户时指定的UID创建的自定义令牌(使用FirebaseAuth.getInstance()。createCustomToken(uid))

AUTH ERROR -> FirebaseError: Expected an ID token, but was given a custom token. AUTH ERROR-> FirebaseError:需要ID令牌,但已获得自定义令牌。

AUTH ERROR -> -7 验证错误-> -7

Using Email/Password auth (firebase.authWithPassword(userMail, userPass, authResultHandler), I get this error: 使用电子邮件/密码身份验证(firebase.authWithPassword(userMail,userPass,authResultHandler),我收到此错误:

AUTH ERROR -> FirebaseError: Error while authenticating. 验证错误-> FirebaseError:验证时出错。

AUTH ERROR -> -999 验证错误-> -999

[PS. [PS。 The Email/Pass login is enable in Firebase authentication page] 在Firebase身份验证页面中启用了电子邮件/密码登录]

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. 我正在使用Java(jvm)构建此桌面界面,以便创建用户并登录他们。

the lib I am using is firebase-admin-6.7.0.jar. 我正在使用的lib是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)... 我注意到在其他库(例如,对于android,js)中,用于验证用户身份的方法在FIREBASE.AUTH (或类似方法)...

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) 在Java(JVM)lib中,有一类FIREBASEAUTH (这是在方法非常相似FIREBASE.AUTH在其他库),但没有这样的方法,如SIGNINWITHCUSTOMTOKENSIGNINWITHEMAIL它(在firebase.auth在其他语言库)

The class FirebaseAuth (jvm) does have the method to create users, but no method to authenticate them (like similar libs in other languages) FirebaseAuth (jvm)类确实具有创建用户的方法,但没有用于验证用户身份的方法(如其他语言中的类似库)

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)... 我发现对用户进行身份验证的唯一方法是在FIREBASE类中,该类具有Firebase.createUser之类的方法以及Firebase.authWithCustomTokenFirebase.authWithPasswordfirebase.authAnonimously等其他登录方法(它们不在FirebaseAuth类中)。 。

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). 因此,要创建一个用户,有两个具有相同方法的类,即Firebase.createUser (无法正常工作)和FirebaseAuth.createUser (可正常工作)。

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. 我相信jvm lib中存在一个错误,用于验证用户身份的方法不在类FirebaseAuth ,而是在Firebase类中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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