Post with Authentication Results in Error 400 (Bad Request)
See original GitHub issueI’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 👍
Issue Analytics
- State:
- Created 7 years ago
- Comments:16
Top Results From Across the Web
How to Fix a 400 Bad Request Error (Causes and Fixes)
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >How to Fix a 400 Bad Request Error: 8 Easy Methods
1. Double Check the Domain Address. One of the most common causes of HTTP status 400 bad request error is a wrong URL....
Read more >POST 400 bad request React authentication
It will be good for you if you console the input, because 400 bad request is related to input and out error (wrong...
Read more >400 Bad Request Error: What It Is and How to Fix It
If an expected custom HTTP header is missing or invalid, a 400 error is a likely result. The client may be uploading a...
Read more >400 Bad Request - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 withFirebaseOptions
like this:I will amend the docs for auth to reflect this.
Here is a workaround, generate the key outside the postAsync() .