![]() |
VOOZH | about |
dotnet add package WebPush --version 1.0.13
NuGet\Install-Package WebPush -Version 1.0.13
<PackageReference Include="WebPush" Version="1.0.13" />
<PackageVersion Include="WebPush" Version="1.0.13" />Directory.Packages.props
<PackageReference Include="WebPush" />Project file
paket add WebPush --version 1.0.13
#r "nuget: WebPush, 1.0.13"
#:package WebPush@1.0.13
#addin nuget:?package=WebPush&version=1.0.13Install as a Cake Addin
#tool nuget:?package=WebPush&version=1.0.13Install as a Cake Tool
<h1 align="center">web-push-csharp</h1>
π CI Build
π Version
π Downloads
Web push requires that push messages triggered from a backend be done via the Web Push Protocol and if you want to send data with your push message, you must also encrypt that data according to the Message Encryption for Web Push spec.
This package makes it easy to send messages and will also handle legacy support for browsers relying on GCM for message sending / delivery.
Installation is simple, just install via NuGet.
Install-Package WebPush
There is a ASP.NET MVC demo project located here
The common use case for this library is an application server using a GCM API key and VAPID keys.
using WebPush;
var pushEndpoint = @"https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6uDLB6....";
var p256dh = @"BKK18ZjtENC4jdhAAg9OfJacySQiDVcXMamy3SKKy7FwJcI5E0DKO9v4V2Pb8NnAPN4EVdmhO............";
var auth = @"fkJatBBEl...............";
var subject = @"mailto:example@example.com";
var publicKey = @"BDjASz8kkVBQJgWcD05uX3VxIs_gSHyuS023jnBoHBgUbg8zIJvTSQytR8MP4Z3-kzcGNVnM...............";
var privateKey = @"mryM-krWj_6IsIMGsd8wNFXGBxnx...............";
var subscription = new PushSubscription(pushEndpoint, p256dh, auth);
var vapidDetails = new VapidDetails(subject, publicKey, privateKey);
//var gcmAPIKey = @"[your key here]";
var webPushClient = new WebPushClient();
try
{
await webPushClient.SendNotificationAsync(subscription, "payload", vapidDetails);
//await webPushClient.SendNotificationAsync(subscription, "payload", gcmAPIKey);
}
catch (WebPushException exception)
{
Console.WriteLine("Http STATUS code" + exception.StatusCode);
}
var subscription = new PushSubscription(pushEndpoint, p256dh, auth);
var options = new Dictionary<string,object>();
options["vapidDetails"] = new VapidDetails(subject, publicKey, privateKey);
//options["gcmAPIKey"] = @"[your key here]";
var webPushClient = new WebPushClient();
try
{
webPushClient.SendNotificationAsync(subscription, "payload", options);
}
catch (WebPushException exception)
{
Console.WriteLine("Http STATUS code" + exception.StatusCode);
}
Note:
SendNotificationAsync()you don't need to define a payload, and this method will work without a GCM API Key and / or VAPID keys if the push service supports it.
Push Subscription
The first argument must be an PushSubscription object containing the details for a push subscription.
Payload
The payload is optional, but if set, will be the data sent with a push message.
This must be a string
Note: In order to encrypt the payload, the pushSubscription must have a keys object with p256dh and auth values.
Options
Options is an optional argument that if defined should be an Dictionary<string,object> containing any of the following values defined, although none of them are required.
setGCMAPIKey().<hr />
VapidDetails vapidKeys = VapidHelper.GenerateVapidKeys();
// Prints 2 URL Safe Base64 Encoded Strings
Console.WriteLine("Public {0}", vapidKeys.PublicKey);
Console.WriteLine("Private {0}", vapidKeys.PrivateKey);
None.
Returns a VapidDetails object with PublicKey and PrivateKey values populated which are URL Safe Base64 encoded strings.
Note: You should create these keys once, store them and use them for all future messages you send.
<hr />
webPushClient.SetGCMAPIKey(@"your-gcm-key");
This method expects the GCM API key that is linked to the gcm_sender_id in
your web app manifest.
You can use a GCM API Key from the Google Developer Console or the Cloud Messaging tab under a Firebase Project.
None.
<hr />
Uri uri = new Uri(subscription.Endpoint);
string audience = uri.Scheme + Uri.SchemeDelimiter + uri.Host;
Dictionary<string, string> vapidHeaders = VapidHelper.GetVapidHeaders(
audience,
@"mailto: example@example.com",
publicKey,
privateKey
);
The GetVapidHeaders() method will take in the values needed to create an Authorization and Crypto-Key header.
The GetVapidHeaders() method expects the following input:
This method returns a Dictionary<string, string> intented to be headers of a web request. It will contain the following keys:
<hr />
<table> <thead> <tr> <th><strong>Browser</strong></th> <th width="130px"><strong>Push without Payload</strong></th> <th width="130px"><strong>Push with Payload</strong></th> <th width="130px"><strong>VAPID</strong></th> <th><strong>Notes</strong></th> </tr> </thead> <tbody> <tr> <td>Chrome</td>
<td>β v42+</td>
<td>β v50+</td>
<td>β v52+</td>
<td>In v51 and less, the gcm_sender_id is needed to get a push subscription.</td>
</tr>
<tr> <td>Firefox</td>
<td>β v44+</td>
<td>β v44+</td>
<td>β v46+</td>
<td></td> </tr>
<tr> <td>Opera</td>
<td>β v39+ Android <strong>*</strong> <br/> <br/> β v42+ Desktop </td>
<td>β v39+ Android <strong>*</strong> <br/> <br/> β v42+ Desktop </td>
<td>β v42+ Desktop</td>
<td>
<strong>*</strong> The gcm_sender_id is needed to get a push subscription.
</td>
</tr>
<tr> <td>Edge</td>
<td>β v17+</td>
<td>β v17+</td>
<td>β v17+</td>
<td></td> </tr> <tr> <td>Safari</td>
<td>β</td>
<td>β</td>
<td>β</td>
<td></td> </tr>
<tr> <td>Samsung Internet Browser</td>
<td>β v4.0.10-53+</td>
<td>β</td>
<td>β</td>
<td>The gcm_sender_id is needed to get a push subscription.</td>
</tr>
</tbody>
</table>
Service Worker Cookbook
The Service Worker Cookbook is full of Web Push examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on WebPush:
| Package | Downloads |
|---|---|
|
Aj.Platform.Core
Biblioteca de Uso Geral para integraΓ§Γ΅es com as API OmsAj |
|
|
DanSaul.SharedCode
Package Description |
|
|
cloudscribe.PwaKit
A set of tools for building a dynamic serviceworker at runtime for ASP.NET Core |
|
|
PushServer.WebPushClientAdapter
Adapter to use WebPush client from https://github.com/web-push-libs/web-push-csharp with PushServer framework for ASP.NET Core 2. |
|
|
LEC.Services.WebPush
Package Description |
Showing the top 3 popular GitHub repositories that depend on WebPush:
| Repository | Stars |
|---|---|
|
notifo-io/notifo
Multi channel notification service for collaboration tools, e-commerce, news service and more.
|
|
|
AiursoftWeb/Kahla
Kahla is a cross-platform business messaging app. Mirror of https://gitlab.aiursoft.com/aiursoft/kahla
|
|
|
Valour-Software/Valour
Valour is bringing communities into the future with unique features, blazing performance, and respect for users.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.13 | 134,936 | 4/28/2026 |
| 1.0.12 | 3,561,167 | 7/3/2021 |
| 1.0.11 | 1,592,446 | 3/30/2018 |
| 1.0.10 | 17,135 | 2/10/2018 |
| 1.0.9 | 60,775 | 4/7/2017 |
| 1.0.8 | 43,447 | 1/23/2017 |
| 1.0.7 | 2,103 | 1/17/2017 |
| 1.0.6 | 2,085 | 1/5/2017 |
| 1.0.5 | 2,355 | 1/2/2017 |
| 1.0.4 | 2,148 | 12/27/2016 |
| 1.0.3 | 3,310 | 12/23/2016 |
| 1.0.2 | 2,085 | 12/23/2016 |
| 1.0.1 | 2,566 | 12/23/2016 |
| 1.0.0 | 3,578 | 12/23/2016 |