Skip to content

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

Open
@SiebeCooreman

Description

@SiebeCooreman

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);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions