-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firebase/GCM push is returning 401 error even though a curl request works as expected #346
Comments
Which version of Rpush are you using?
|
I'm using rPush, 2.7.0 @aried3r the latest one. |
I'm using Rpush 2.7.0 as well on a production server with FCM and it works without problems. My only guess is that it's a configuration error, since it seems to connect to the FCM server just fine, but with a 401 HTTP code. Can you please double check your configuration and check your logs as well for the full error message? |
Thanks for replying @aried3r The logs return the same error, Rpush::DeliveryError, Unable to deliver notification 8, received error 401 (Unauthorized, check your App auth_key.) The strange thing is when I do a curl request, it works 100%. So I don't think my keys/registration-id's are off. But maybe I'm setting the variables incorrectly? The main server key is the Rpush::Gcm::App auth_key, correct? That's what I set for it. And obviously when sending the actual push, the registration_id is the id matched with the phone for Rpush::Gcm::Notification registration.ids data is just a simple message. So I don't know where the auth error is breaking since the CURL request works? |
I'm using Postman to test this, although it works just fine using Rpush. I set two headers, according to the docs which Rpush does as well. The value of the I guess somewhere in your code where you build notifications you have something similar to the following, heavily simplified code: app = Rpush::Gcm::App.find_by(name: 'android_app')
puts "App auth_key: #{app.auth_key}" or where you already have your notification: puts notification.app.auth_key The payload I used in Postman is very simple, please replace the registration ID with a valid one: {
"registration_ids": ["invalid"],
"data": {
"foobar": "bazbar"
},
"dry-run": true
} I cannot really help you any further with debugging, since it does not seem to be Rpush's fault. Check if you are using the newer, shorter Server Keys. I guess you already know, but this SO post also explains how to get there in the FCM Console. However, we are still using the old "legacy" server keys in a project and that also works for us (as they are still supported). |
Closing since there was no more activity. I'll reopen if necessary. |
Here a sample curl to save time for any dev researching this and wanting to test:
|
I believe I set up everything correctly, and trying to test with a simple one device registration ID push. However, I keep getting the 401 error even though I know for a fact the keys work, i.e. I do a regular curl on http://fcm.googleapis.com/fcm/send using the SAME server_key I set up for the Rpush::Gcm::App as well as the same registration ID I intended to send the message to. Because the curl works perfectly, I don't think it's actually an auth_key issue even though Rpush keeps telling me Unauthorized, check your App auth_key.
Any ideas what I could have done to set it up incorrectly?
I set up the new app like so...
app = Rpush::Gcm::App.new
app.name = "android_app"
app.auth_key = "..."
app.connections = 1
app.save!
And tested a push like so...
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("android_app")
n.registration_ids = ["..."]
n.data = { message: "hi mom!" }
n.save!
Rpush.push returns the 401...
The text was updated successfully, but these errors were encountered: