简体   繁体   中英

Firebase Authentication + Firebase Storage in Unity3d

I can't understand how to pass the values of authentication in the storage... Below is the error which is returned when attempting to write the file, and below the code itself. Has anyone faced such a problem?

Permission rules use the standard

service firebase.storage {
  match /b/project.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

System.AggregateException: Exception of type 'System.AggregateException' was thrown. ----------------- Firebase.Storage.StorageException: User does not have permission to access this object. ---> System.IO.IOException: The server has terminated the upload session --- End of inner exception stack trace ---

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Storage;
using Firebase.Auth;

public class Storage : MonoBehaviour {
    public Texture2D texture;

    public Auth autentification;

    FirebaseApp app;
    AppOptions options;

    FirebaseStorage storage;
    StorageReference storage_ref, ref_file;

    // Use this for initialization
    void Start () {
        InitFirebase ();
    }

    public void InitFirebase(){
        print("InitFirebase start");

        DependencyStatus dependencyStatus = FirebaseApp.CheckDependencies();

        if (dependencyStatus != DependencyStatus.Available) {
            FirebaseApp.FixDependenciesAsync().ContinueWith(task => {
                dependencyStatus = FirebaseApp.CheckDependencies();
                if (dependencyStatus == DependencyStatus.Available) {
                    Signin();
                } else {
                    print("Could not resolve all dependencies: " + dependencyStatus);
                }
            });
        } else {
            Signin();
        }
    }

    public void Signin(){
        print("Signin start");
        string _testEmail = "test@gmail.com";
        string _testPassword = "qwerty";

        options = new AppOptions ();
        options.ApiKey = "API_KEY";
        options.StorageBucket = "STORAGE_BUCKET";
        options.AppId = "APPID";

        app = FirebaseApp.Create (options, "name");

        FirebaseAuth.GetAuth(app).SignInWithEmailAndPasswordAsync (_testEmail, _testPassword).ContinueWith ((System.Threading.Tasks.Task<FirebaseUser> authTask) => {
            if (authTask.IsCanceled) {
                print("signin canceled");
            } else if (authTask.IsFaulted) {
                print("signin faulted " + authTask.Exception.ToString());
            } else if (authTask.IsCompleted) {
                print("signin complete , user id is " + authTask.Result.UserId);    
                storage = FirebaseStorage.GetInstance(app);    
                storage_ref = storage.GetReferenceFromUrl("gs://testproject-3b976.appspot.com/data/");
                Upload ("images/" + texture.name + ".png");
            } else {
                print("signin unknown error");
            }
        });
    }

Firebase Authentication with UnitySDK doesn't work on UnityEditor now.(also standalone)
https://github.com/firebase/quickstart-unity/issues/3
Have you tried it only on UnityEditor? It may work on iOS or Android.

However, I am also looking for ways to use Firebase Authentication on standalone game with Unity3D.
Using Firebase Authentication with Unity on standalone game

If you have already tried it on iOS or Android and then ask this, I have nothing anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM