esl / MongoosePush

MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Apache License 2.0
108 stars 24 forks source link

Unauthorized error #132

Closed jobomix closed 4 years ago

jobomix commented 4 years ago

Hi,

I am running mongoosePush 1.0.6 with Docker I am using the following end point POST /v2/notification/{device_id} to send a message to FCM. I got a valid device_id and I tested it through FCM. It all works fine. I am making a post to my endpoint with the following payload : { "service": "fcm", "data": { "body": "notification's text body", "title": "notification's title" } }

When posting I get the following error

push | 2019-12-17T10:17:00.265 [info] <0.1620.0> Reconnecting to push service provider before request push | 2019-12-17T10:17:00.349 [error] <0.1620.0> Error code 401 ({:badmatch, {:error, {:invalid, "<", 0}}}): Unauthorized push | 2019-12-17T10:17:00.349 [warning] <0.1683.0> Unable to complete push request due to unknown error: {:badmatch, {:error, {:invalid, "<", 0}}} push | 2019-12-17T10:17:00.349 [debug] <0.1683.0> Sent 500 in 84ms

My docker compose:

push: container_name: "push" hostname: "push" image: 'mongooseim/mongoose-push:1.0.6' environment: PUSH_APNS_ENABLED: "false" PUSH_HTTPS_CERTFILE: "/opt/app/priv/ssl/rest_cert.pem" PUSH_HTTPS_KEYFILE: "/opt/app/priv/ssl/rest_key.pem" PUSH_LOGLEVEL: "debug" ports:

  • "443:8443" volumes:
  • ./push/priv:/opt/app/priv

The cert is valid on the https endpoint. did I do something wrong?

Thanks

rslota commented 4 years ago

Hi @jobomix ,

Base on the compose file you've sent, FCM server auth token seems to be missing, thus there is a problem with authorization with FCM.

jobomix commented 4 years ago

Hi @rslota,

Thanks for the quick response.

The token.json is under /opt/app/priv/fcm/token.json. Do I need to add an extra config variable? BTW I ve just tried the latest docker image with the same config and it all works, so it looks like the problem is inherent to the 1.0.6. I would prefer to use a stable release for what I need to do

rslota commented 4 years ago

Current stable release 1.0.6 does not support FCMv1 API, which I'm assuming you're trying to use. 1.0.6 supports so called "legacy" FCM API, which requires string-only token configurable via env variable. Please refer to documentation in README.md for correct version of MongoosePush. In this case - https://github.com/esl/MongoosePush/blob/1.0.6/README.md .

jobomix commented 4 years ago

OK that explains it.

Thanks