firebase-admin-go
firebase-admin-go copied to clipboard
SubscribeToTopic() results in 401
[REQUIRED] Step 2: Describe your environment
- Operating System version:
$ uname -a
Linux Chicago 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
- Firebase SDK version: firebase.google.com/go/v4 v4.10.0
- Library version: v4.10.0
- Firebase Product: messaging
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
app, err := firebase.NewApp(context.Background(), &firebase.Config{
ProjectID: projectID,
})
fcm, err := app.Messaging(context.Background())
if err != nil {
panic(err)
}
...
fcm.SubscribeToTopic(context.Background(), []string{
"<valid token>",
}, "anyTopic")
Results in the error:
unexpected http response with status: 401\n<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n
Inspecting this further, based on the documentation here: https://developers.google.com/instance-id/reference/server#manage_relationship_maps_for_multiple_app_instances
I would expect that /iid/v1:batchAdd
gets called with the corresponding parameters. However, it doesn't have an authorization header.
Did I miss something super obvious in configuration?
We had this issue for days now. Turns out the service account we were using only needed the roles/firebase.admin
role. No idea if there's a more strict role that still allows it to work as the docs aren't very clear about it
@kevmo314 Did you ever find a fix?
@kevmo314 Did you ever find a fix?
I did, actually. In my case it wasn't the permissions issue that @caioaao mentioned above, but rather that you can only subscribe to so many topics. In our code, we had too many subscriptions being created and after enough subscriptions it starts throwing 401 Unauthorized
.
I don't know why Google chose to throw a 401 instead of a more informative 429 or something.
@kevmo314 Did you ever find a fix?
I did, actually. In my case it wasn't the permissions issue that @caioaao mentioned above, but rather that you can only subscribe to so many topics. In our code, we had too many subscriptions being created and after enough subscriptions it starts throwing
401 Unauthorized
.I don't know why Google chose to throw a 401 instead of a more informative 429 or something.
Thanks for responding. This is my first topic, so I don't think that's the issue, but I appreciate the suggestion!
@balloman Did you find the root cause? I faced the same issue when subscribing to my first topic, and it only happened with subscription requests.
@NguyenTrongCuong I don't remember if we found a fix to be honest, sorry