Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription no longer valid. Details: push subscription has unsubscribed or expired. #94

Open
SiebeCooreman opened this issue Jul 26, 2022 · 0 comments

Comments

@SiebeCooreman
Copy link

SiebeCooreman commented Jul 26, 2022

Me and my team have been trying to implement the web push notifications with our .NET 6 backend.

When ran on localhost, everything works perfectly. Pushing and receiving a notification works like a charm.

However, when we deploy our application to Azure, we run into trouble.
We've set the .env variables in the configuration of our app in Azure configuration,
but an error 410

Subscription no longer valid. Details: push subscription has unsubscribed or expired.

is thrown.

The weird thing is, when we use the same keypair and subscriber credentials in our local development, the notification gets sent and actually gets received in the Azure deployed React app. Even if we set our launchSettings.json to be production.

Some sources online suggest that a subscription might change over time, but this does not explain the fact that it does go through locally and doesn't when deployed. Why is this happening? Are we missing some kind of (deployment-)configuration?

For reference, here are some configs/files that we use:

appsettings.Development.json (keys were generated with the VapidHelper.GenerateVapidKeys(); method)

  "VapidKeys": {
    "PublicKey": "XXXXXXXXXXXXXXX",
    "PrivateKey": "XXX"
  }
async private Task SendNotification(List<NotificationCredential> devices,string payload)
    {
        string vapidPublicKey = _configuration["VapidKeys:PublicKey"];
        string vapidPrivateKey = _configuration["VapidKeys:PrivateKey"];
        
        Console.WriteLine(vapidPublicKey);
        Console.WriteLine(vapidPrivateKey);
        // both in development AND in production these keys are printed!

        var webPushClient = new WebPushClient();
        var vapidDetails = new VapidDetails("mailto:[email protected]", vapidPublicKey, vapidPrivateKey);
        

        foreach (var device in devices)
        {
            var pushSubscription = new PushSubscription(device.Endpoint, device.P256dh, device.Auth);
            await webPushClient.SendNotificationAsync(pushSubscription, payload, vapidDetails);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant