4

I am trying to implement Firebase Cloud Messaging into a Web App. I am following this guide from Google. I have already implemented the client side and I want to subscribe my client to a topic with the token my client sends to my server. The guide says subscribing is done over the Instance ID API from google.

The problem is that the Instance ID API only returns "401 Unauthorized" when I provide my Firebase API-Key in the Authorization header and "403 forbidden" when I pass my Cloud messaging Server-Key as Authorization.

Here is one of the calls I tried from Postman

POST /iid/v1/{{CLIENT_TOKEN}}/rel/topics/movies HTTP/1.1
Host: iid.googleapis.com
Authorization: key={{API_KEY}
Content-Type: application/json
Content-Length: 0
Cache-Control: no-cache
Postman-Token: 3cb43dd8-bc27-4fab-b97b-c5ef583c4191

In the Code snippet I have omitted the CLIENT_TOKEN and the API_KEY. the token is the token received from calling messaging.getToken() on the client.

AL.
  • 36,815
  • 10
  • 142
  • 281
ninjaintrouble
  • 424
  • 4
  • 10
  • You indicate you tried using the "Firebase API-Key". The key should be the "Server key" shown on the Cloud Messaging tab of your Project Settings in the Firebase Console. Is that what you used? – Bob Snyder May 06 '18 at 22:19
  • Yes, im using the server key from the cloud messaging tab. When I use the server key I get 403 Acess forbidden from the Instance id endpoint. – ninjaintrouble May 07 '18 at 09:06
  • 403 means that the link is forbidden from your end. Are you accessing the API from your company/school which might have a firewall of some sort? It's possible that it's preventing you from sending requests. Try using a different network. – AL. May 07 '18 at 16:20
  • I tried connecting from a standard home network and from a public network. Both didn't work. – ninjaintrouble May 08 '18 at 06:05
  • 1
    @ninjaintrouble I have the same issue. how did you solve that ? – Miuranga Sep 21 '18 at 12:38
  • @Miuranga Not really a solution but I ended up using the firebase sdk instead of the API. – ninjaintrouble Sep 18 '19 at 10:31
  • @Miuranga Did you solve the issue? I have the same, basically, I have two projects: dev and production basically with the same settings and same APIs enable except that production has billing enabled and is on blaze plan, while dev is on spark plan. The key from dev version works, but the one from production does not. – pkacprzak Oct 02 '19 at 16:49

0 Answers0