Firebase身份验证限制

Firebase身份验证限制

本文介绍了Firebase身份验证限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Firebase的新成员,因此深表谢意。我正在编写Java服务器端测试代码。我从数据库中抓取了几个用户,并试图将数据迁移到Firebase中的用户身份验证节点。我的代码从数据库中选择一些用户,为每个用户创建一个新的线程。

第一个线程连接并验证成功。随后的同时身份验证尝试失败,并显示下面的错误消息。每个线程都有自己的Firebase引用对象实例。同时登录的次数是否有限制,可能来自同一个IP地址?在文档中还找不到任何东西。



如果我将代码更改为在单个线程中运行并逐个登录并注销每个用户,那么我不会收到错误消息。
$ b

消息:-5 
消息:由于另一个身份验证尝试,此身份验证尝试已被中止,才能完成。

Firebase ref =新的Firebase(https://< instance> .firebaseio.com /);

ref.authWithPassword(mEmail,mPassword,new Firebase.AuthResultHandler(){
@Override
public void onAuthenticated(AuthData authData){
System.out.println (成功验证:+ mEmail);
user.setUID(authData.getUid());
user.setCurrentUserRef(ref);
done.set(true);

$ b @Override
public void onAuthenticationError(FirebaseError firebaseError){
System.out.println(Authentication error:+ mEmail);
System。 out.println(验证错误:+ ref.toString());

System.out.println(Message:+ firebaseError.getCode());
System。 out.println(Message:+ firebaseError.getDetails());
System.out.println(Message:+ firebaseError.getMessage());

done.set(真);
}});
waitForCompletion(this.getClass()。getName());


解决方案

,使用是更好的解决方案。

Firebase连接在任何给定时间最多只能有一个用户身份验证。但是,在Firebase Java库中,有一个未公开的(而不是官方支持的)解决方法来创建多个独立的连接。在 com.firebase.client 包中的类中,可以运行以下代码:

  //重要的代码需要在包中com.firebase.client 
Config config1 = new Config();
Config config2 = new Config();
Firebase ref1 =新的Firebase(https://< your-firebase> .firebaseio.com,config1);
Firebase ref2 =新的Firebase(https://< your-firebase> .firebaseio.com,config2);
// ref1和ref2现在有独立的连接,监听器和认证状态

这些还将打开与服务器的独立连接。


I am new to Firebase so any insights appreciated. I'm writing Java server side test code. I grab several users from an database and am trying to migrate the data into user authenticated nodes within Firebase. My code selects a few users from the DB and spins up a new thread for each user.

The first thread connects and authenticates successfully. Subsequent simultaneous authentication attempts fail with the error message below. Each thread has its own instance of a Firebase reference object. Is there a restriction on the number of simultaneous logins, perhaps from the same IP address? Haven't been able to find anything in the documentation yet.

If I change the code to run in a single thread and login and logout each user one by one then I do not receive an error.

Any insights much appreciated.

Message: -5
Message: Due to another authentication attempt, this authentication attempt was aborted before it could complete.

            Firebase ref = new Firebase("https://<instance>.firebaseio.com/");

            ref.authWithPassword(mEmail, mPassword, new Firebase.AuthResultHandler() {
            @Override
            public void onAuthenticated(AuthData authData) {
                System.out.println("Successfully authenticated: " + mEmail);
                user.setUID(authData.getUid());
                user.setCurrentUserRef(ref);
                done.set(true);
            }

            @Override
            public void onAuthenticationError(FirebaseError firebaseError) {
                System.out.println("Error during authentication: " + mEmail);
                System.out.println("Error during authentication: " + ref.toString());

                System.out.println("Message: " + firebaseError.getCode());
                System.out.println("Message: " + firebaseError.getDetails());
                System.out.println("Message: " + firebaseError.getMessage());

                done.set(true);
            }});
            waitForCompletion(this.getClass().getName());
解决方案

If you are authenticating as different users because of security rules, using a server token is the better solution.

A Firebase connection can only have at most one user authenticated at any given time. However in the Firebase Java library there is an undocumented (and not officially supported) workaround to create multiple independent connections. In a class that is in the package com.firebase.client you can run the following code

// important this code needs to be in the package com.firebase.client
Config config1 = new Config();
Config config2 = new Config();
Firebase ref1 = new Firebase("https://<your-firebase>.firebaseio.com", config1);
Firebase ref2 = new Firebase("https://<your-firebase>.firebaseio.com", config2);
// ref1 and ref2 will now have independent connections, listeners and authentication states

Note that these will also open independent connections to the server.

这篇关于Firebase身份验证限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:52