You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Push notifications for ASP.NET Core Blazor Progressive Web Applications (PWAs)
@@ -30,24 +31,21 @@ The example in this article uses push notifications to provide order status upda
30
31
31
32
Generate the cryptographic public and private keys for securing push notifications either locally, for example with PowerShell or IIS, or using an online tool.
32
33
33
-
> [!CAUTION]
34
-
> This article's use of a unencrypted, insecure private key in the app's code ***is for demonstration purposes and local testing only.*** We recommend using a secure approach for supplying a private key to an ASP.NET Core app at all stages of development. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
35
-
36
-
<!-- We'll expand this article to include explicit guidance on key management with AKV. A
37
-
Google search with 'get certificate private key from azure key vault for use in c# code'
38
-
generates a decent code sample. I didn't see such a good starting point in AKV Learn
39
-
articles, so we'll use the AI-generated code as a starting point.
40
-
41
-
The preceding CAUTION statement also appears in the 'Send a notification' section.
42
-
-->
43
-
44
34
Placeholders used in this article's example code:
45
35
46
36
*`{PUBLIC KEY}`: The public key.
47
37
*`{PRIVATE KEY}`: The private key.
48
38
49
39
For this article's C# examples, update the `[email protected]` email address to match the address used when creating the custom key pair.
50
40
41
+
When implementing push notifications, ensure that cryptographic keys are managed securely:
42
+
43
+
***Key generation**: Use a trusted library or tool to generate the public and private keys. Avoid using weak or outdated algorithms.
44
+
***Key storage**: Store private keys securely on the server, using a secure storage mechanism such as a hardware security module (HSM) or encrypted storage. Never expose private keys to the client.
45
+
***Key usage**: Use the private key only for signing push notification payloads. Ensure that the public key is distributed securely to clients.
46
+
47
+
For more information on cryptographic best practices, see [Cryptographic Services](/dotnet/standard/security/cryptographic-services).
48
+
51
49
## Create a subscription
52
50
53
51
Before sending push notifications to a user, the app must ask the user for permission. If they grant permission to receive notifications, their browser generates a *subscription*, which includes a set of tokens the app can use to route notifications to the user.
@@ -258,7 +256,7 @@ Sending a notification involves performing some complex cryptographic operations
258
256
The `SendNotificationAsync` method dispatches order notifications using the captured subscription. The following code makes uses of `WebPush` APIs for dispatching the notification. The payload of the notification is JSON serialized and includes a message and a URL. The message is displayed to the user, and the URL allows the user to reach the pizza order associated with the notification. Additional parameters can be serialized as required for other notification scenarios.
259
257
260
258
> [!CAUTION]
261
-
> This article's use of a unencrypted, insecure private key in the app's code ***is for demonstration purposes and local testing only.*** We recommend using a secure approach for supplying a private key to an ASP.NET Core app at all stages of development. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
259
+
> In the following example, we recommend using a secure approach for supplying the private key. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
0 commit comments