I'm having some issues doing an authenticated request to Firebase.
I have a token generated but when I send it to Firebase I always get an Unauthorized request.
response when I send the access_token
in the request. The strange part is that it works without the param.
I even tested with no access rules, but I get the same result.
When I send curl 'https://<PROJECTID>.firebaseio.com/events.json'
I get the expect values back, but if I send curl 'https://<PROJECTID>.firebaseio.com/events.json?access_token=<TOKEN>'
the answer is
{ "error" : "Unauthorized request." }
I've tried sending it in the header like curl -H "Authorization: Bearer <TOKEN>" https://<PROJECTID>.firebaseio.com/events.json
but does not work either.
If I enforce some rules in the database the initial request with no token gives me
{ "error" : "Permission denied" }
but I still get { "error" : "Unauthorized request." }
if I send the token.
Any help would be much appreciated.
UPDATE
Managed to fix it. I was not getting the token properly. After checking this thread I noticed I was not sending https://www.googleapis.com/auth/userinfo.email
in the scopes
array when doing the request for the token. After adding it works fine.
UPDATE 2
As mentioned by Xin Meng this is pretty clear in the Firebase Authenticate REST Requests documentation as well.