firebase-database-dotnet: Post with Authentication Results in Error 400 (Bad Request)
I’ve got some pretty simple code which should create a new ClassRoom object and save it to Firebase under “classRooms”. If I change my authentication rules in the database to allow universal access and I remove the authentication part of the request, everything works fine. So I think the issue has something to do with authentication.
Here’s the code which makes the request:
String id = subjectId.Text;
String name = subjectName.Text;
String activity = this.activity.Text;
var classRoom = await firebase
.Child("classRooms")
.WithAuth(auth.FirebaseToken)
.PostAsync<ClassRoom>(new ClassRoom(id, name, activity));
And here’s the ClassRoom class:
class ClassRoom
{
public String subjectId;
public String subjectName;
public String activity;
public ClassRoom(String subjectId, String subjectName, String activity)
{
this.subjectId = subjectId;
this.subjectName = subjectName;
this.activity = activity;
}
}
Thanks so much for any time anyone puts in to this. Your efforts are much appreciated 👍
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16
Commits related to this issue
- Describes issues in #22 — committed to step-up-labs/firebase-database-dotnet by bezysoftware 8 years ago
Hi folks, sorry for taking so long to reply, I was on vacation. Anyway, the solution mentioned by @jaybowman will work, however that’s not the preferred way of doing it. I will actually obsolete the “WithAuth” method and remove it later completely.
The preferred way of doing auth is using the
FirebaseClient’s constructor withFirebaseOptionslike this:I will amend the docs for auth to reflect this.
Here is a workaround, generate the key outside the postAsync() .