danhper / elixir-web-push-encryption

Elixir implementation of Web Push Payload encryption.
https://hex.pm/packages/web_push_encryption
MIT License
59 stars 42 forks source link

Erro on send_web_push #4

Closed jhonathas closed 6 years ago

jhonathas commented 6 years ago

Hello,

I tried to use the dependency but it gives an error of UnauthorizedRegistration. Should I be able to pass the public_key and private_key generated by vapid? Here I am always having the error:


iex (24)> {: ok, response} = WebPushEncryption.send_web_push (body, subscription)
{:OK,
 % HTTPoison.Response {body: "<HTML> \ n <HEAD> \ n <TITLE> UnauthorizedRegistration </ TITLE> \ n </ HEAD> \ n <BODY BGCOLOR = \" # FFFFFF \ "TEXT = \" # 000000 \ n </ H1> \ n <H2> Error 400 </ H2> \ n </ BODY> \ n </ HTML> \ n ",
  headers: [{"Content-Type", "text / html; charset = UTF-8"},
   {"Date", "Fri, 12 Jan 2018 18:32:18 GMT"},
   {"Expires", "Fri, 12 Jan 2018 18:32:18 GMT"},
   {"Cache-Control", "private, max-age = 0"},
   {"X-Content-Type-Options", "nosniff"}, {"X-Frame-Options", "SAMEORIGIN"},
   {"X-XSS-Protection", "1; mode = block"}, {"Server", "GSE"},
   {"Alt-Svc",
    "hq = \": 443 \ "; ma = 2592000; quic = 51303431; quic = 51303339; quic = 51303338; ​​quic = 51303337; quic = 51303335, quic = "41,39,38,37,35"
   {"Accept-Ranges", "none"}, {"Vary", "Accept-Encoding"},
   {"Transfer-Encoding", "chunked"}],
  request_url: "https://fcm.googleapis.com/fcm/send/f4XnofrrDNA:APA91bGhHaI8QgrQBGymQfcPUxyaSjW7lgSR8hUQEB_Jc9NLFfEk722ma9yyXaVQIA_3oPrkAclF9f7Hw88rxdzTB0BPVJMQT28HObOhm1S76FjphSWO8Qgc2JKVFIrG5vhpkPQP4VOD"
  status_code: 400}}

[update] 2018-01-16

I tried some tests but I could not get it to work, I'm using vapid and I tried to create a Crypto module itself to use my own Public and Private keys, but I still did not succeed. Would you help me?

[update] 2018-01-17

Trying to come up with a solution, I found this link [https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol] and I noticed that the Authentication part is missing from the header, in order to send a signature JWT when the endpoint is fcm.googleapis.com/fcm.

arjan commented 6 years ago

See my PR, #6

arjan commented 6 years ago

This one can be closed now, I guess. @jhonathas can you confirm it's working for you?

danhper commented 6 years ago

I will close, please comment here if it still does not work.

jhonathas commented 6 years ago

@arjan @tuvistavie

It worked perfectly: D Thank you very much.

arjan commented 6 years ago

You're welcome!