Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.Firebase and Authentication

I have used Xamarin.Firebase in VS-Xamarin-Android to connect to firebase storage database from my android app.
It raises exception saying that "User does not have permission to access this object"...I can't figure out what to do with Firebase.Auth namespace.
Can anyone help me;
Sample below:

FirebaseOptions o = new FirebaseOptions.Builder()
.SetApiKey(Application.Context.GetString(Resource.String.firebasestoragekey))
.SetApplicationId(Application.Context.GetString(Resource.String.firebaseappid))
.Build();
FirebaseApp fa = FirebaseApp.InitializeApp(Application.Context, o);
FirebaseStorage fs = Firebase.Storage.FirebaseStorage.Instance;
StorageReference sr = fs.GetReferenceFromUrl(storagefile);
File localFile = File.CreateTempFile(filename, "jpg", Android.OS.Environment.ExternalStorageDirectory);
sr.GetFile(localFile).AddOnSuccessListener(listener).AddOnFailureListener(listenerf);

Tagged:

Posts

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    You will need to login/auth with Firebase, or open up permissions. I could not get Auth to work (not even Anonymous sign in).

    Maybe you have more luck, this is what I've been trying to do:

    var auth = FirebaseAuth.GetInstance(firebaseApp);
    var authListener = new MyFirebaseAuthListener();

    authListener.AuthStateChanged += (object sender, EventArgs e) =>
    {
    var firebaseUser = ((MyFirebaseAuthListener)sender).Auth.CurrentUser;
    };

    auth.AddAuthStateListener(authListener);

    auth.SignInWithCustomToken(firebaseToken).AddOnCompleteListener(new SigninCompleteListener());
    auth.SignInAnonymously().AddOnCompleteListener(new SigninCompleteListener());

    class SigninCompleteListener : Java.Lang.Object, IOnCompleteListener
    {
    public void OnComplete(Android.Gms.Tasks.Task task)
    {
    if (!task.IsSuccessful)
    {
    UserDialogs.Instance.Alert(task.Exception.Message);
    }
    }
    }

  • AnthonyClarkAnthonyClark USMember

    @PanagiotisKotsibos I was able to get Auth working after about a week of messing around. I uploaded to github if you would like to check it out.

    https://github.com/Anth0ny229/FirebaseTest

    You will have to change MainLauncher in each activity since I reused the UI and mostly just tested one at a time.
    The database writing works as well but I have my database setup as default where the user must be authenticated.

    Also, I had to add my Certificate Fingerprints (SHA-1) for my app.

Sign In or Register to comment.