Firebase 身份验证限制 [英] Firebase Authentication Limits

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

问题描述

我是 Firebase 的新手,因此对任何见解表示赞赏.我正在编写 Java 服务器端测试代码.我从数据库中获取了几个用户,并尝试将数据迁移到 Firebase 中的用户身份验证节点.我的代码从数据库中选择了几个用户,并为每个用户启动一个新线程.

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.

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

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.

非常感谢任何见解.

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.

一个 Firebase 连接在任何给定时间最多只能对一个用户进行身份验证.但是,在 Firebase Java 库中,有一种未记录(且未正式支持)的解决方法来创建多个独立的连接.在包 com.firebase.client 中的类中,您可以运行以下代码

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 身份验证限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆