Closed IlyaSV closed 4 years ago
I'm getting this same error unless I change my Firebase Storage rules to allow all read/write. With the default rules (shown below). After I authorize a user via the FirbaseAuthentication.net process, I'm able to read and write to Firebase Database, but not Storage. I'm getting the 403: "Permission denied. Could not perform this operation" error.
Any help is appreciated.
Firebase Storage rules (these are the default rules): service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write: if request.auth != null; } } }
Firebase Login code (works for reads/writes to Database):
var auth = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));
var token = await auth.SignInWithEmailAndPasswordAsync(firebaseUsername, firebasePassword);
firebase = new FirebaseClient(
firebaseUrl,
new FirebaseOptions
{
AuthTokenAsyncFactory = () => Task.FromResult(token.FirebaseToken)
});
loginSuccessfulLabel.Text = "Login Successful";
Firebase storage code to upload .png image file (where 403 error is received). This same code works fine when Firebase storage rules are set to allow all read/write:
async void UploadImage_Clicked(object sender, System.EventArgs e)
{
var stream = File.Open("picture2.png", FileMode.Open);
var task = new FirebaseStorage("xxxxxxx.appspot.com")
.Child("data")
.Child("picture2.png")
.PutAsync(stream);
task.Progress.ProgressChanged += (s, ex) => Console.WriteLine($"Progress: { ex.Percentage} %");
downloadURL = await task;
}
I'm having the same issue. I'm using my firebase server key. Same as when I create a FirebaseClient. I get this error "Response status code does not indicate success: 403 (Forbidden)." When I open up the storage rule to allow write: if true; I can save the file. Please help.
private async Task<string> SaveUserPhoto(string uid, Stream photoStream)
{
var task = new FirebaseStorage(_StorageBucket, new FirebaseStorageOptions()
{
AuthTokenAsyncFactory = () => Task.FromResult(_firebaseServerKey)
})
.Child("residentPhotos")
.Child(uid)
.Child("profile.jpg")
.PutAsync(photoStream);
// Track progress of the upload
task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");
// await the task to wait until upload completes and get the download url
var downloadUrl = await task;
return downloadUrl;
}
I was able to authenticate using a user account. just follow the simpleConsole sample code. I would still be nice to use some type of service account.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing the issue due to inactivity. Feel free to re-open
any request with service account auth token return error 403: "Permission denied. Could not perform this operation".