web-push-libs / web-push-csharp

Web Push library for C#
Mozilla Public License 2.0
429 stars 108 forks source link

403/401 in all cases... #62

Closed Mayzz03 closed 3 years ago

Mayzz03 commented 5 years ago

Hello,

I got 403 or 401 error in all cases.

I tried with:

For each I tried with gcm and vapid

vapid is from FCM console, but I tried to generate with the lib.

Any idea ?

Dim pushEndpoint As String = "https://fcm.googleapis.com/fcm/send/fioYOFKVMzg:APA91bE0mgSMyjVP....."
Dim p256dh As String = "BPG78SwSOmn....."
Dim auth As String = "I5v6fE....."

Dim subject As String = "mailto:email@gmail.com"
Dim publicKey As String = "BPnuPx7jaYffa....."
Dim privateKey As String = "GlIBY68...."

Dim subscription = New PushSubscription(pushEndpoint, p256dh, auth)
Dim vapidDetails = New VapidDetails(subject, publicKey, privateKey)
Dim gcmAPIKey = "123145684"

Dim webPushClient = New WebPushClient()
Try
   webPushClient.SendNotification(subscription, Nothing, vapidDetails)
   'webPushClient.SendNotification(subscription, "payload", gcmAPIKey)
Catch ex As WebPushException
            Console.WriteLine("Http STATUS code" & ex.StatusCode)
End Try
coryjthompson commented 5 years ago

401 Unauthorized and 403 is Forbidden.

Have you tried the demo project? https://github.com/coryjthompson/WebPushDemo

OliLeclerc commented 5 years ago

Hi, I am also having some problems with status code 403, but the demo project works, so it my code that does not work. I was therefore wondering about why we have this part: var p256dh = base64Encode(subscription.getKey('p256dh')); var auth = base64Encode(subscription.getKey('auth')); EDIT: Adding the encoding worked for me.

iseec commented 5 years ago

I might have a similar problem at hand.

When i use your package in my Dev Environment everything works like a charm even with remote debugging on my phone, so i sent it up to our staging Environment, which runs the application dockerized as micro services in the cloud.

Now i get the 403, any ideas whats causing this, could it be the different IP Addresses for service worker and Push Service?

The only difference which i could find so far, is that the dev environment is windows 10 and the stage are ubuntu containers.

girishbhatt84 commented 5 years ago

I have similar problem and found out if i don't use VAPID key generated by Web-Push dll than it works fine. I just need to copy VAPID from google recommended site. Do you have any idea why VAPID generated by dll is not working?

iseec commented 5 years ago

@girishbhatt84 which site did you use to generate your VAPID key? So i can check if this would work for me too.

girishbhatt84 commented 5 years ago

@epandasa Sorry for delay response, i used https://web-push-codelab.glitch.me/ but now i see even web-push-csharp library is working fine, not sure how but now all the generated key works. One tips: try to send subscription as it is from front-end to back-end without any kind of parsing, i suspect that could be a reason for error as well.