web-push-php
web-push-php copied to clipboard
Unable to send notifications to Microsoft Edge. (401 Unauthorized response) Works fine on Chrome and Firefox.
NOTE: Please test in a least two browsers (i.e. Chrome and Firefox). This helps with diagnosing problems quicker.
Please confirm the following:
- [X ] I have read the README entirely
- [X ] I have verified in the issues that my problem hasn't already been resolved
Setup
Please provide the following details, the more info you can provide the better.
- Operating System: <Linux | Windows | OS X> Linux
- PHP Version: <5.6 | 7.0 | ...> 7.3
- web-push-php Version: <1.0.0> 5.2
Please check that you have installed and enabled these PHP extensions :
- [ x] gmp
- [ x] mbstring
- [ x] curl
- [ x] openssl
Please select any browsers that you are experiencing problems with:
- [ ] Chrome
- [ ] Firefox
- [ ] Firefox for Mobile
- [ ] Opera for Android
- [ ] Samsung Internet Browser
- [ x] Other
Please specify the versions (i.e. Chrome Beta, Firefox Beta etc). Microsoft Edge 44.18362.449.0
Problem
So I am able to subscribe a user and save the endpoint and keys. I am also able to send the notification to Chrome and Firefox users. When sending to Microsoft Edge I get the error : 401 Unauthorized The Vapid keys are setup correctly ( thats how it works for Chrome and Firefox. Endpoint seems to be https://sg2p.notify.windows.com/.......
Please explain what behaviour you are seeing.
Expected
Please explain what you expected to happen
Features Used
- [ ] VAPID Support
- [x ] GCM API Key
- [ x] Sending with Payload
Example / Reproduce Case
Here is an example of the output [x] Message failed to sent for subscription https://sg2p.notify.windows.com/w/?token=BQYAAABJ1kl24AOKrMHjEzJGi2KuK7rOiv//d+oHwTbqS/l3wSh0ufoyWDxmswANey0hrcJqFjDy5J3XOsw0RKp6aEy5vzOSu18SbxLCRGI6dSrqv8A1X1Tl02UyV7ZCSCvASRSBsIjzSMMNnbd5ivSnxsoltAEb/2ItJX2jxv8kygB68AbYZJ07S/I1FwrnGc6WMPKB7wgJNTDgpvGFSImic5RhfYJnAoVtwaNdCoWiUQccCyXGks+PGYOWEKYBHcCB9OKWKSUfYEi6MPSN0TzzpVDNaFR+8GzOUi3XZKe0IkUeLAF10IrAFrQH0SfsmbOhsEZy4qjMkOxMd1Yg2brlBNxK:
Client error: POST https://sg2p.notify.windows.com/w/?token=BQYAAABJ1kl24AOKrMHjEzJGi2KuK7rOiv//d+oHwTbqS/l3wSh0ufoyWDxmswANey0hrcJqFjDy5J3XOsw0RKp6aEy5vzOSu18SbxLCRGI6dSrqv8A1X1Tl02UyV7ZCSCvASRSBsIjzSMMNnbd5ivSnxsoltAEb/2ItJX2jxv8kygB68AbYZJ07S/I1FwrnGc6WMPKB7wgJNTDgpvGFSImic5RhfYJnAoVtwaNdCoWiUQccCyXGks+PGYOWEKYBHcCB9OKWKSUfYEi6MPSN0TzzpVDNaFR+8GzOUi3XZKe0IkUeLAF10IrAFrQH0SfsmbOhsEZy4qjMkOxMd1Yg2brlBNxK resulted in a 401 Unauthorized response
Other
Please put any remaining notes here.
I have the same problem...
I found the solutions here!!! https://github.com/web-push-libs/web-push-php/issues/174#issuecomment-398460130
The field endpoint on DB must be VARCHAR 500
Any working solution for EDGE?
Hey, I just noticed that there seems to be an issue with the Push Registration Endpoint that gets sent from the Browser Client and the handling in PHP itself.
Basically, the Browser sends the Endpoint like this: https://par02p.notify.windows.com/w/?token=BQYAAA......W...YBy19%2fHl6XYsbdDB8PeKyAEvlmRWR9n4.....CBdpeFRLSsc....S1fx1Rreyemxk8%2f6x....RZ4tyeCESbxox26guKD4cUn....gzsnxaoL16%2fpGP2xNY.....S5G5x5ytrDP....vPaA8ee....eEkEBDnqRdS9Q2Oo3YJW%2f....a8esub5T%2b0sd4hvOaIGsV7rNZEMb.....9xxg%2b7z7QZGaedkn2OHVuatMOW......kRyBb (redacted some of the token for reason with ...)
Notice how the token query parameter is already urlencoded?
When the data gets to the backend side in PHP, the Endpoint seems to get there already urldecoded, which then results in the push server not recognizing it and resulting in a 401 error.
This is just a hint, I guess. Combined with the larger table field and this, you can easily get it to work.
Edit: Actually, turned out in my case it was a tiny piece of code my co-worker just told me about, which automatically urlencodes the request data on the server side - which caused the issue, so make sure to not modify the endpoint either in the client or server.
@dfun90 Thank you so much for your answer!!! (three exclamation marks because I'm excited) You've just saved me from further pulling my hairs out after 1.5 days of fruitless debugging why the push messages weren't working on chromium only. What's funny - it's the edited part that helped me.
It turned out that I've been unnecessarily de-encoding the "endpoint" string in my POST controller before putting it into the database...
On a similar note, I am having issues with Apple devices like iPad and iPhone. Does it work with Apple devices/IOS?
@dfun90
Hey, I just noticed that there seems to be an issue with the Push Registration Endpoint that gets sent from the Browser Client and the handling in PHP itself.
Basically, the Browser sends the Endpoint like this:
https://par02p.notify.windows.com/w/?token=BQYAAA......W...YBy19%2fHl6XYsbdDB8PeKyAEvlmRWR9n4.....CBdpeFRLSsc....S1fx1Rreyemxk8%2f6x....RZ4tyeCESbxox26guKD4cUn....gzsnxaoL16%2fpGP2xNY.....S5G5x5ytrDP....vPaA8ee....eEkEBDnqRdS9Q2Oo3YJW%2f....a8esub5T%2b0sd4hvOaIGsV7rNZEMb.....9xxg%2b7z7QZGaedkn2OHVuatMOW......kRyBb(redacted some of the token for reason with ...)Notice how the
tokenquery parameter is already urlencoded? When the data gets to the backend side in PHP, the Endpoint seems to get there already urldecoded, which then results in the push server not recognizing it and resulting in a 401 error.This is just a hint, I guess. Combined with the larger table field and this, you can easily get it to work.
Edit: Actually, turned out in my case it was a tiny piece of code my co-worker just told me about, which automatically urlencodes the request data on the server side - which caused the issue, so make sure to not modify the endpoint either in the client or server.
Excellent! I ran into the same problem. Only the Edge browser returned error 401. This detail that the URL code was being changed when sending to the server would be the last thing I would check. That's if I actually noticed it. lol This post was the only thing I could find on the internet about this error. Thank you so much!
I found the solutions here!!! #174 (comment)
The field endpoint on DB must be VARCHAR 500
That was the solution for my problem: our DB field was set to VARCHAR 200 (what was working for Chrome and iOS push notifications, but Microsoft's needs 419 characters for its endpoint. So setting to VARCHAR 500 solved it :-)