WebPush Notification Send Results in 403 #1
Description
Hello
I used your demo as a blueprint to implement the push subscriptions for our customers.
I can subscribe users, and also send notifications to them in my development environment.
So i pushed it up to staging, but now i get the 403 with the same code.
(with new subscriptions for the new environment).
Exception:
Received unexpected response code: 403 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() --- End of stack trace from previous location where exception was thrown --- at WebPush.WebPushClient.HandleResponse(HttpResponseMessage response, PushSubscription subscription) at WebPush.WebPushClient.<SendNotificationAsync>d__15.MoveNext() at WebPush.WebPushClient.<SendNotificationAsync>d__16.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Backend.Notifications.MessageHandler.NotificationBatchMessageHandler.<Handle>d__11.MoveNext() in /app/src/Backend/Notifications/MessageHandler/NotificationBatchMessageHandler.cs:line 93
For the Subscriptions, they are done via a website run in docker containers behind a Loadbalancer, the public endpoint of the Loadbalancer is served via Https, and the containers run on different machines in a private subnet.
The Communication between the Loadbalancers and Containers is established via HTTP.
Code to send Notifications:
var notification = GenerateNotification(batch.Template, account);
string notificationjson = string.Empty;
try
{
if (await _repo.RecordNotificationSent(subscription.Id, batch.Template.Id,
notification.NotificationId.ToString()))
{
notificationjson = JsonConvert.SerializeObject(notification);
_client = new WebPushClient();
await _client.SendNotificationAsync(ToWebPushSubscription(subscription),
notificationjson, _vapidDetails);
}
}
catch (WebPushException ex)
{
if(ex.Message == "Subscription no longer valid")
{
Logger?.LogInformation($"invalidate subscription {subscription.Id}");
await _ar.UnsubscribePushAsync(subscription);
}
else
{
Logger?.LogCritical(ex.Message, ex);
}
}
catch (Exception ex)
{
Logger?.LogCritical(ex.Message, ex);
}
...
private WebPush.PushSubscription ToWebPushSubscription(PushSubscription sub)
{
return new WebPush.PushSubscription(sub.Endpoint, sub.P256Dh, sub.Auth);
}
Environment Settings:
- dotnet core 1.1.1
- webpush version: 1.0.11
Development Environment:
- windows 10 Pro & VS Community 2019 16.2.2
Staging Environment:
- containers based on microsoft/dotnet:1.1.1-sdk
WebServer: Kestrel
Any Ideas what could cause this issue, and how to fix it?