Firebase suddenly stopped working using anonymous Auth

I installed firebase storage for my application and added code for anonymous authorization in the application and on the firebase console.

it worked at first, but I don’t know why it stopped working, stating that the user does not have permission to access the object

Anonymous authorization is configured correctly, and I saw how it works, the code is almost like Google Firebase documents

LogCat:

D / FirebaseAuth: signInAnonymously: onComplete: true
D / FirebaseAuth: onAuthStateChanged: signed_in: (arbitrary auth user ID)

... when I request an element from firebase

E / StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.FirebaseException: An internal error has occurred. Error internal error. I / DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor W / NetworkRequest: no auth token for E / StorageException request: A StorageException event occurred. The user does not have permission to access this object. Code: -13021 HttpResult: 403

Can anyone help?

Variable declaration

private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

in the OnCreate method

mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d("FirebaseAuth", "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d("FirebaseAuth", "onAuthStateChanged:signed_out");
            }
            // ...
        }
    };
    mAuth.signInAnonymously()
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d("FirebaseAuth", "signInAnonymously:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w("FirebaseAuth", "signInAnonymously", task.getException());
                        Toast.makeText(SingleMemeEditor.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });

and the method that comes from the repository:

    Bitmap bmp;
    final Context lContext = context; //getting the MainActivity Context
    final String lFileName = fileName; //filename to download
    final String lCatPath = catPath; //internal categorization folder

    FirebaseStorage storage = FirebaseStorage.getInstance();
    // Create a storage reference from our app
    StorageReference storageRef = storage.getReferenceFromUrl(context.getResources().getString(R.string.firebase_bucket));
    // Create a reference with an initial file path and name
    StorageReference filesRef = storageRef.child("files/" + fileName);
    try
    {
        final File localFile = File.createTempFile("images", "jpg");

        filesRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>()
        {
            @Override
            public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot)
            {
                // Local temp file has been created
                File file = new File(getDirectory(lContext)
                        + File.separator + lCatPath + File.separator + lFileName);
                try
                {
                    Boolean b = file.createNewFile();
                    if(b)
                    {
                        FileInputStream in = new FileInputStream(localFile);
                        FileOutputStream out = new FileOutputStream(file);

                        // Transfer bytes from in to out
                        byte[] buf = new byte[(int)localFile.length()];
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        in.close();
                        out.close();
                    }
                            Drawable.createFromPath(file.getPath())).getBitmap());
                }
                catch (IOException ex)
                {
                    // Handle any errors
                    Log.e("CopyingFromTemp", ex.getMessage());
                }

            }
        }).addOnFailureListener(new OnFailureListener()
        {
            @Override
            public void onFailure(@NonNull Exception ex)
            {
                // Handle any errors
                Log.e("FirebaseDownloadError", ex.getMessage());
            }
        });
    }
    catch(Exception ex)
    {
        Log.e("FirebaseDownloadError", ex.getMessage());
    }

I also use standard safety rules:

match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
+4
source share
4 answers

, , , , - , .

signInAnonymously

mAuth.signOut();

!

!

EDIT: , , ( firebase, , , ).

, :

if (mAuth.getCurrentUser() != null)
        {
            mAuth.getCurrentUser().reload();
        }
        else
        {
            mAuth.signInAnonymously()
                    .addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
                    {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            Log.d("FirebaseAuth", "signInAnonymously:onComplete:" + task.isSuccessful());

                            // If sign in fails, display a message to the user. If sign in succeeds
                            // the auth state listener will be notified and logic to handle the
                            // signed in user can be handled in the listener.
                            if (!task.isSuccessful())
                            {
                                Log.w("FirebaseAuth", "signInAnonymously", task.getException());
                                Toast.makeText(MainActivity.this, "Authentication failed.",
                                        Toast.LENGTH_SHORT).show();
                            }
                            // ...
                        }
                    });
        }

() .

+4

"W/NetworkRequest: no auth token " .

, Firebase Storage . . , , , , - , ( ), (. ).

 //this sets completely open access to your data
 allow read, write;

, , , , . , , , , .

+3

firebase.

  allow read, write: if request.auth != null;
0
source

Someday, disconnect it from the firebase database, so connect your firebase authentication application to android studio through the firebase help tool.

0
source

All Articles