Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to authenticate using service account #4

Closed
IlyaSV opened this issue Apr 10, 2017 · 5 comments
Closed

Unable to authenticate using service account #4

IlyaSV opened this issue Apr 10, 2017 · 5 comments
Labels

Comments

@IlyaSV
Copy link

IlyaSV commented Apr 10, 2017

any request with service account auth token return error 403: "Permission denied. Could not perform this operation".

@TennisDrum
Copy link

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;
        }

@jaybowman
Copy link

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;
        }

@jaybowman
Copy link

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.

@stale
Copy link

stale bot commented Mar 2, 2020

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.

@stale stale bot added the stale label Mar 2, 2020
@stale
Copy link

stale bot commented Mar 9, 2020

Closing the issue due to inactivity. Feel free to re-open

@stale stale bot closed this as completed Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants