Closed felipeoliveirar closed 4 years ago
I'm using version 2.0.2 and firebaseAuthentication.net 3.0.5, here is how my code looks.
var token = _auth.FirebaseToken;
var query = await _client.Child(_userCollection)
.Child(userId)
.WithAuth(() => { return token; })
.OnceSingleAsync
my _client doesn't have the .WithAuth()
Yes, I had the same issue with version 3.0.2 so I reverted back to 2.0.2 which was working for me. Sorry I could not help.
no problem. Thanks for help me.. :D
I have it working with the new 3.0.2 version. At first I got an error. Then I recompiled the firebase.dll from the src folder that is available from the nuget package. Then everything works. I guess the firebase.database package uses an auth token on all db calls, even if the Firebase db rules don't require it.
How you did it? Can you print and post here? the step by step. After you did it you change all to .WithAuth() ?
With Version 3.0.2 there is not a public .WithAuth() method. Here is my initialization code.
var config = new FirebaseConfig("my firebase api key"); var authProvider = new FirebaseAuthProvider(config);
string user = System.Configuration.ConfigurationManager.AppSettings["firebaseUser"]; string pw = System.Configuration.ConfigurationManager.AppSettings["firebasePw"];
_auth = await authProvider.SignInWithEmailAndPasswordAsync(user, pw);
_fbClient = new FirebaseClient(_basePath,
new FirebaseOptions()
{
AuthTokenAsyncFactory = () => Task.FromResult(_auth.FirebaseToken)
});
Then in my getUser() (the users firebase collection has an authenticated user rule to retrieve users.)
var query = await _client.Child(_userCollection)
.Child(userId)
// .WithAuth(() => { return token; }) // previous version needed the withAuth()
.OnceSingleAsync
return query;
hum.. Thanks @jaybowman I will try it here.. thanks
@jaybowman I didn't find the FirebaseConfig are you using the FirebaseDatabase.net ? or the FirebaseAuth of Xamarin?
I am making my connection this way:
if (_client == null)
{
_client = new FirebaseClient(
baseUrl: Constantes.Constantes.STRING_URL,
options: new FirebaseOptions
{
OfflineDatabaseFactory = (t, s) => new OfflineDatabase(t, s),
});
databaseOffline = _client.Child("Cliente").AsRealtimeDatabase<Cliente>();
databaseOffline.SyncExceptionThrown += (s, ex) => Console.WriteLine(ex.Exception);
}
adn the request this way
var itemsonline = _client
.Child("Cliente")
.OnceAsync<Cliente>();
var retornodoservidor = await itemsonline;
var listitemsnoservidor = retornodoservidor.ToList();
I'm using: package id="FirebaseAuthentication.net" version="3.0.5" targetFramework="net452" package id="FirebaseDatabase.net" version="3.0.2" targetFramework="net452"
My app is a commandline console application, not a Xamarin mobile app.
hum.. thanks @jaybowman .. I will try to do here..
@jaybowman when I try to connect.. appear when I try to sigging. return an exeption null. where i get this "my firebase api key". on google.json? I took that one. but didn't work
For my console app I'm using the firebase apikey from firebase web config. The API key is a little different for each firebase app type (Android - google-services.json, IOS - GoogleServices-info.plist, and web).
keeps return null :( i don't know how to make that works..
@jaybowman I did a new project just with this method of login and password.. but ever when I try to auth with mail and password.. it returns null. in your api-key you just insert it or make some change? I.E: https://your-api-key ??
I have this same problem with 'the simplest solution' (could not parse auth token):
var auth = "ABCDE"; // your app secret
var firebaseClient = new FirebaseClient(
"
When I use FirebaseAuthentication.net and setup anonymous access in Firebase and then the code works: var config = new FirebaseConfig(FirebaseSettings.authKey); var authProvider = new FirebaseAuthProvider(config);
var auth = await authProvider.SignInAnonymouslyAsync();
this.fbClient = new FirebaseClient(
FirebaseSettings.endPoint,
new FirebaseOptions
{
AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken)
});
Then I can write to the database. But what I want is a database that is readonly for users but write-enabled for my server side code by app only token. How do I achieve this? Different question: I created my collection by hand. Is it possible to create (if not exists) this from within the .Net code using this library?
@bezysoftware Any updates? I have absolutely the same issue. The simplest example does not work at all? I use my Web ApiKey and the latest version from Nuget 3.3.3
Hi Folks - I'm having the same issue - do I need to do something special with the basic example? Is Firebase supposed to be set up with Anonymous access for this library to work?
Cheers.
Andrew
Update on this - you need to use the now legacy Firebase Database Secret to get this to work. Apparently Firebase has deprecated this method of authentication so I would not bank on this working long term. That said my code started to magically work when I used the key from the Database Secrets portion of the project config.
Hope this helps,
Andrew
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
Hi. can you help me with this issue. When I send the token in firebase option happens this error.