AlphaOmega.PushSharp.WebPush 1.0.19

dotnet add package AlphaOmega.PushSharp.WebPush --version 1.0.19
                    
NuGet\Install-Package AlphaOmega.PushSharp.WebPush -Version 1.0.19
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AlphaOmega.PushSharp.WebPush" Version="1.0.19" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlphaOmega.PushSharp.WebPush" Version="1.0.19" />
                    
Directory.Packages.props
<PackageReference Include="AlphaOmega.PushSharp.WebPush" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AlphaOmega.PushSharp.WebPush --version 1.0.19
                    
#r "nuget: AlphaOmega.PushSharp.WebPush, 1.0.19"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AlphaOmega.PushSharp.WebPush@1.0.19
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AlphaOmega.PushSharp.WebPush&version=1.0.19
                    
Install as a Cake Addin
#tool nuget:?package=AlphaOmega.PushSharp.WebPush&version=1.0.19
                    
Install as a Cake Tool

PushSharp.WebPush

Auto build Nuget

What's new

  1. Updated NuGet packages to the latest versions
  2. Added assembly signature (PublicKeyToken=a8ac5fc45c3adb8d)
  3. Added PE file signing. (S/N: 00c18bc05b61a77408c694bd3542d035)
  4. Added CI/CD pipelines
  5. Limited number of builds: .NET 4.8 and .NET Standard 2.0 only (I will gladly return the rest if needed.)
  6. Removed generic options argument and replaced with strongly typed parameters.
  7. Changed SetGcmApiKey(...) from method to property.
  8. Marked GcmApiKey property as deprecated.

Why

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.

Install

Installation is simple, just install via NuGet.

Install-Package AlphaOmega.PushSharp.WebPush

Demo Project

There is a ASP.NET MVC Core demo project located here

Usage

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: vapidDetails);
    //await webPushClient.SendNotificationAsync(subscription, "payload", gcmAPIKey: gcmAPIKey);
}
catch (WebPushException exception)
{
	Console.WriteLine("Http STATUS code" + exception.StatusCode);
}

API Reference

SendNotificationAsync(pushSubscription, payload, vapidDetails|gcmAPIKey, cancellationToken)

var subscription = new PushSubscription(pushEndpoint, p256dh, auth);

var vapidDetails = new VapidDetails(subject, publicKey, privateKey);
// var gcmAPIKey = "[your key here]";

var webPushClient = new WebPushClient();
try
{
	webPushClient.SendNotificationAsync(subscription, "payload", vapidDetails: vapidDetails, gcmAPIKey: gcmAPIKey);
}
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.

Input

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

  • gcmAPIKey can be a GCM API key to be used for this request and this request only. This overrides any API key set via GcmApiKey property.
  • vapidDetails should be a VapidDetails object with subject, publicKey and privateKey values defined. These values should follow the VAPID Spec.
  • TTL is a value in seconds that describes how long a push message is retained by the push service (by default, four weeks).
  • headers is an object with all the extra headers you want to add to the request.

GenerateVapidKeys()

VapidDetails vapidKeys = VapidHelper.GenerateVapidKeys();

// Prints 2 URL Safe Base64 Encoded Strings
Console.WriteLine("Public {0}", vapidKeys.PublicKey);
Console.WriteLine("Private {0}", vapidKeys.PrivateKey);
Input

None.

Returns

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.


GcmApiKey(apiKey) [deprecated]

webPushClient.GcmApiKey = "your-gcm-key";
Input

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.

Returns

Previously this method returned the current GCM API key, but now it is deprecated.


GetVapidHeaders(audience, subject, publicKey, privateKey, expiration)

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.

Input

The GetVapidHeaders() method expects the following input:

  • audience: the origin of the push service.
  • subject: the mailto or URL for your application.
  • publicKey: the VAPID public key.
  • privateKey: the VAPID private key.
Returns

This method returns a Dictionary<string, string> intended to be headers of a web request. It will contain the following keys:

  • Authorization
  • Crypto-Key.

Help

Service Worker Cookbook

The Service Worker Cookbook is full of Web Push examples.

Credits

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.19 241 10/11/2025
1.0.18 125 10/11/2025
1.0.17 203 10/8/2025
1.0.14 205 10/8/2025
1.0.13 203 10/8/2025