Closed matbrady closed 2 years ago
@matbrady looking at the response seems like something isn't right with the FIREBASE_KEY
can you view your logs to verify that when you start the rails server the environment variables are loaded? You can just try to print the ENV["FIREBASE_KEY"]
to your logs in the controller.
Closing since it looks like an environment configuration issue for the user. @matbrady feel free to reopen if you find its a problem in the gem
API Version
Legacy HTTP
Problem
From the app server I am able to:
Full Method
```ruby def self.send_notification_to_users(tokens, title, body, data = {}) fcm = FCM.new( ENV["FIREBASE_KEY"] ) message = { 'notification': { title: title, body: body, }, } response = fcm.send(tokens, message) end ```produces a successful 200 response:
However, running the same
FcmHelper.send_notification_to_users
method above within a controller action produces a 401 authentication error:Full response
``` {"body":"\u003cHTML\u003e\n\u003cHEAD\u003e\n\u003cTITLE\u003eINVALID_KEY\u003c/TITLE\u003e\n\u003c/HEAD\u003e\n\u003cBODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\"\u003e\n\u003cH1\u003eINVALID_KEY\u003c/H1\u003e\n\u003cH2\u003eError 401\u003c/H2\u003e\n\u003c/BODY\u003e\n\u003c/HTML\u003e\n","headers":{"content-type":"text/html; charset=UTF-8","date":"Wed, 12 Jan 2022 15:14:17 GMT","expires":"Wed, 12 Jan 2022 15:14:17 GMT","cache-control":"private, max-age=0","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","content-security-policy":"frame-ancestors 'self'","x-xss-protection":"1; mode=block","server":"GSE","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","connection":"close","transfer-encoding":"chunked"},"status_code":401,"response":"There was an error authenticating the sender account." ```Question
Any thoughts on why messages would be sent successfully via the console but have an authentication error from within controller logic?