管理画面では、メール認証と匿名ログインの両方を有効にしています。データにはノードが 1 つだけあります - Hello: "World"
私が持っているルールは
{
"rules": {
".read": "auth != null",
//".read": true,
".write": true
}
}
ユーザーが上記のルールでログインしていない場合、The read failed: Permission denied That's all good. が表示されます。
匿名ユーザーがログインしている場合、値 "{Hello=World"} が表示されます。これまでのところ機能しています。
メール ユーザーでログインすると、次のエラーが表示されます :FirebaseError: Permission denied
onAuthenticate がトリガーされ、次のようになります: ユーザー ID: 3c6ce912-a05a-49ed-ae68-8ec97d022303、プロバイダー: パスワード
完全なコードは以下のとおりです。私は何を間違っていますか?
import com.firebase.client.AuthData;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class FirebaseTest {
Firebase ref = new Firebase("https://<FIREBASE NAME>.firebaseio.com/");
public FirebaseTest() {
//logonAnonymous(); //works
logonEmail(); //permission denied
showValues();
try {
System.out.println("Waiting for input");
System.in.read();
} catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void logonAnonymous() {
ref.authAnonymously(new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
// we've authenticated this session with your Firebase app
System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
System.out.println("Anon user auth error " + firebaseError.toString());
}
});
}
private void logonEmail() {
ref.authWithPassword("myuser@home.com", "secret", new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
}
});
}
public void showValues() {
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println( " value -" + snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
}