1

我是Firebase的新用戶,因此深表感謝。我正在編寫Java服務器端測試代碼。我從數據庫中抓取了多個用戶,並試圖將數據遷移到Firebase中的用戶身份驗證節點。我的代碼從數據庫中選擇一些用戶,爲每個用戶創建一個新線程。Firebase身份驗證限制

第一個線程連接並驗證成功。隨後的同時身份驗證嘗試失敗,並顯示以下錯誤消息。每個線程都有自己的Firebase參考對象實例。同時登錄的數量是否有限制,可能來自同一個IP地址?尚未能在文檔中找到任何內容。

如果我將代碼更改爲在單個線程中運行並逐個登錄並註銷每個用戶,那麼我不會收到錯誤。

任何洞察力非常讚賞。

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()); 
+2

交叉帖子:https://groups.google.com/forum/#!topic/firebase-talk/qxqPAy1PIO8 –

回答

4

如果您驗證以不同的用戶因爲安全規則,使用server token是更好的解決方案。

Firebase連接在任何給定時間最多隻能有一個用戶身份驗證。但是,在Firebase Java庫中,存在未記錄(且未正式支持)的解決方法以創建多個獨立連接。在一類是在包com.firebase.client你可以運行下面的代碼

// 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 

注意,這些也將打開到服務器的獨立連接。

+0

是的,我正在使用基於用戶的安全規則。 https:// /users/simplelogin:xx/data 謝謝我將探索這兩個選項。我認爲每個Firebase對象只能維持一個連接。我所做的是創建一個線程池,池中的每個線程都有自己的非共享Firebase對象。我認爲每個Firebase對象都可以有獨立的連接。但我無法用自己的連接維護每個線程。我研究令牌。謝謝。 – mba12

+0

我可以證實這一點。儘管如此,這還是有點冒險的。是否有計劃更自然地讓API支持這一點? – mlohbihler