Giter VIP home page Giter VIP logo

web-push-csharp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

web-push-csharp's Issues

Can't resolve fcm.googleapis.com

While running sendNotificationMethod I get exception

System.AggregateException occurred
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
 at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at WebPush.WebPushClient.SendNotification(PushSubscription subscription, String payload, VapidDetails vapidDetails)
   at iResort.App_Code.WebPushWrapper.<>c__DisplayClass9_0.<Notify>b__0(String data) in C:\Users\sezer.yilmaz\source\repos\iResort\iResort\App_Code\WebPushWrapper.cs:line 92
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at iResort.App_Code.WebPushWrapper.Notify(Int32 id, String topic, String message, String url, String icon) in C:\Users\sezer.yilmaz\source\repos\iResort\iResort\App_Code\WebPushWrapper.cs:line 83
   at iResort.app.testNotification.Page_Load(Object sender, EventArgs e) in C:\Users\sezer.yilmaz\source\repos\iResort\iResort\app\testNotification.aspx.cs:line 17
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Inner Exception 1: HttpRequestException: An error occurred while sending the request. 
Inner Exception 2: WebException: The remote name could not be resolved: 'fcm.googleapis.com'

And have no any idea why it happens. Can you help me?

UnauthorizedRegistration (400)

            Dim vapidDetails As New WebPush.VapidDetails("mailto:[email protected]", My.Settings.PushPublicKey, My.Settings.PushPrivateKey)

            Dim Serializer As New Web.Script.Serialization.JavaScriptSerializer
            Dim subscrpObj As Dictionary(Of String, Object) = Serializer.DeserializeObject(Context.Properties("REGISTRATIONBLOB"))

            Dim Keys As Dictionary(Of String, Object) = subscrpObj("subscription")("keys")

            Dim Endpoint As String = subscrpObj("subscription")("endpoint")
            Dim p265dh As String = Keys("p256dh")
            Dim Auth As String = Keys("auth")

            Dim subscrp As New WebPush.PushSubscription(Endpoint, p265dh, Auth)

            Dim push As New WebPush.WebPushClient
            push.SendNotification(subscrp, "", vapidDetails)

Payload used:

{"subscription":{"endpoint":"https://fcm.googleapis.com/fcm/send/cVZGX8otWpE:APA91bFSgTN2vcviHTOgGA66pAAxPLZbMdQS5hPKvEyBfTV5aIEN...","expirationTime":null,"keys":{"p256dh":"BHZfAmES5nxERWtcwf-h...=","auth":"OUab3C..."}}}

I've read in some documentation TTL is a required value, but I'm not seeing it here. Also, I don't know why Subject is needed. What is the email/URL used for?

Used this in conjunction: https://serviceworke.rs/push-simple.html

403/401 in all cases...

Hello,

I got 403 or 401 error in all cases.

I tried with:

  • fcm url (from Chrome)
  • gcm url (Opera)
  • Mozilla url (firefox)

For each I tried with gcm and vapid

vapid is from FCM console, but I tried to generate with the lib.

Any idea ?

Dim pushEndpoint As String = "https://fcm.googleapis.com/fcm/send/fioYOFKVMzg:APA91bE0mgSMyjVP....."
Dim p256dh As String = "BPG78SwSOmn....."
Dim auth As String = "I5v6fE....."
 
Dim subject As String = "mailto:[email protected]"
Dim publicKey As String = "BPnuPx7jaYffa....."
Dim privateKey As String = "GlIBY68...."

Dim subscription = New PushSubscription(pushEndpoint, p256dh, auth)
Dim vapidDetails = New VapidDetails(subject, publicKey, privateKey)
Dim gcmAPIKey = "123145684"

Dim webPushClient = New WebPushClient()
Try
   webPushClient.SendNotification(subscription, Nothing, vapidDetails)
   'webPushClient.SendNotification(subscription, "payload", gcmAPIKey)
Catch ex As WebPushException
            Console.WriteLine("Http STATUS code" & ex.StatusCode)
End Try

SendNotification hangs

Hi,
Whenever my server executes the SendNotification method it hangs and not returning from it.
The notification, however, is successfully recived on client's service worker.
This is my code:

var vapidPrivateKey = "MI-X-.............x3w";
var vapidDetails = new VapidDetails("mailto:myemailaddress", "BErTgwJ.........", vapidPrivateKey);
var subscription = new PushSubscription(Endpoint, P256dh, Auth);
var webPushClient = new WebPushClient();
try
{
    var msg = new Msg() { title = "new message title", content = "new content, WOW!" };
    webPushClient.SendNotification(subscription,
            Newtonsoft.Json.JsonConvert.SerializeObject(msg, Newtonsoft.Json.Formatting.None),
            vapidDetails);
}
catch (WebPushException exception)
{
    Console.WriteLine("Http STATUS code" + exception.StatusCode);
}
catch (Exception e)
{
}

Any ideas?
Since I do get the notification, I think my code is fine, but....
Thanks

Support for full framework missing

Hi Cory,

RE: #18

I don't know what happened, but the support for full frameworks is gone with the 1.0.10 version. I'm back to square one where your package wants to import a huge bunch of extra crap into my project, because it supports all kind of "Core" and "Standard" things, but completely overlooks that I might already have all that in my full framework (net45, net46 or net47) and don't need a second version installed.

Look at that:

image

I need your package and probably a full framework version of BouncyCastle. Nothing else. The rest will just put a bunch of incompatible stuff in my project.

Can you please bring back support for the full framework?

Request stay pending

Request stay pending

The request at browser stay pending when the method is not async.

I'll make a pull request with the fix wich worked for me.

Danke

Details on integration with Angular

Hi,

It took me a while to make it work with angular due to payload format and maybe this will be useful for others or maybe added in docs.

In angular 5 the client side processing is typically done in a ngsw-worker.js file and it probably integrates well with node.js api but in order to make it work it needs a specific payload format.

In short the sending of the notification should be done like this:

webPushClient.SendNotification(subscription, JsonConvert.SerializeObject(new { notification = new {title = "title", body = "message"} }), vapidDetails);

where the inner notification object accepts properties from the webpush standard :

//https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification
// 0:"actions"
// 1:"body"
// 2:"dir"
// 3:"icon"
// 4:"lang"
// 5:"renotify"
// 6:"requireInteraction"
// 7:"tag"
// 8:"vibrate"
// 9:"data"

thees values are taken from NOTIFICATION_OPTION_NAMES with debug (see bellow js code)

code from ngsw-worker.js:

    async handlePush(data) {
        this.broadcast({
            type: 'PUSH',
            data,
        });
        if (!data.notification || !data.notification.title) {
            return;
        }
        const desc = data.notification;
        let options = {};
        NOTIFICATION_OPTION_NAMES.filter(name => desc.hasOwnProperty(name))
            .forEach(name => options[name] = desc[name]);
        this.scope.registration.showNotification(desc['title'], options);
    }

Notice that if it doesn't find expected format it just returns and you won't see anything on the browser.

 if (!data.notification || !data.notification.title) {
            return;
 }

Exception while passsing the payload parameter

Hi, I am able to send the the simple notification without the payload but when I pass the payload parameter an exception is thrown
webPushClient.SendNotification(subscription, @"payload");

the exception text is: FormatException: Invalid point encoding 63
Where I am doing wrong?

Replace AesFastEngine with AesEngine.

Util/Encryptor.cs(73,49): warning CS0618: 'AesFastEngine' is obsolete: 'Use AesEngine instead' [/home/travis/build/web-push-libs/web-push-csharp/WebPush/WebPush.csproj]

System.AggregateException

Hi,

I got this issue when I called
webPushClient.SendNotification(subscription, "payload", options);

I'm trying to migrate from php script Web Push to C#, so I check in php all keys, and it seems to work (using VAPID)

Do you have any ideas?

Exception levée : 'System.AggregateException' dans mscorlib.dll
done à System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
à System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
à WebPush.WebPushClient.SendNotification(PushSubscription subscription, String payload, Dictionary`2 options)

support for safari

I have a hard requirements to implement web push notifications. Do we know if there any blockers to make web push work with safari, and Edge ?

Firefox support

Hi,

i have a problem with firefox support. It's great working for chrome, but for firefox I received Unauthorize http status code.

I suppose it's a bug in c# library, because when I'm using the same keys with Node.js version (https://web-push-codelab.appspot.com/) all it's working fine.

Could you check this?

P.S. Thank you very much for this library! Good job!

WebPush not found

I have installed the package from NuGet and am attempting to write a Web API controller to register the subscription.
Somehow none of your libraries are being recognized. Instead I only see a lib called "WebApiPush.Controllers"

using System;
using System.Web.Http;

namespace WebApiPush.Controllers
{
    [RoutePrefix("api")]
    public class PushController : ApiController
    {

        // POST api/<controller>
        [Route("push")]
        public void Post(dynamic value)
        {
            string pushEndpoint = value.endpoint;
            dynamic keys = value.keys;
            string auth = keys.auth;
            string p256dh = keys.p256dh;

            var subject = @"mailto:[email protected]";
            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 webPush = new WebPush();
            try
            {
                webPush.SendNotification(subscription, "payload", vapidDetails);
            }
            catch (WebPushException exception)
            {
                Console.WriteLine("Http STATUS code" + exception.StatusCode);
            }
        }
    }
}

image
Sorry if I am doing this all wrong... I am very new to web push.
Thanks.

Improve the error message when the request fails

Can you add the response content to the exception message?
It will help immensely when getting started.

In HandleResponse:

// you might want to have a try/catch, there are cases when reading
// the content fails (although it should work in most cases)
var str = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
throw new WebPushException($"{message}. Details: {str}", response.StatusCode, response.Headers, subscription);

Before

WebPush.WebPushException: 'Received unexpected response code: 403'

After

WebPush.WebPushException: 'Received unexpected response code: 403. Details: the key in the authorization header does not correspond to the sender ID used to subscribe this user. Please ensure you are using the correct sender ID and server Key from the Firebase console.

Compatibility with .net core 1.1

Thanks for this library.. but it seems the current version and one of the dependency (BouncyCastle) are not compatible with .net core 1.1.
Will there be a release for .net core 1.1 compatible version anytime soon?

Package WebPush 1.0.9 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package WebPush 1.0.9 supports: net40 (.NETFramework,Version=v4.0)

Package BouncyCastle 1.8.1 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package BouncyCastle 1.8.1 supports: net (.NETFramework,Version=v0.0)

FCM endpoints not supported

registration endpoint for FCM device are sent without server key , caousing a 401 unauthorized response.

Probably caused by code below from webPushClient

var isGcm = subscription.Endpoint.StartsWith(@"https://android.googleapis.com/gcm/send"); if (isGcm)

adding FCM endpoint should solve the issue , as FCM should be backward compatible (tested )

var isGcm = subscription.Endpoint.StartsWith(@"https://android.googleapis.com/gcm/send") || subscription.Endpoint.StartsWith(@"https://fcm.googleapis.com/fcm/send/"); if (isGcm)

Getting a conversion exception

When sending notification I get: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

I can't figure what the input is, but i think it's one of the generated keys.

I have run all the Validate methods in the VapidHelper and everything goes fine.

private string _publicKey = @"BCvlec_uZKKZDzrf45jKLdAfLGBdKJZHjS7NsZt9GR-vW_iNF7mpbF-RKcq4nIbOeIkCYoDfG51njrtzFSTvT3E";
        private string _privateKey = @"oSj0DmpXB6shtz7bLHdk6EiiTtKIkhyR_QPIdtxIIrM";
        private string _subject = @"mailto:[email protected]";

           var headers = GetVapidHeaders(notification.Endpoint);

            var subscription = new PushSubscription(notification.Endpoint, headers["Crypto-Key"], headers["Authorization"]);

            var options = new Dictionary<string, object>();
            options["vapidDetails"] = new VapidDetails(_subject, _publicKey, _privateKey);

                var webPushClient = new WebPushClient();
                webPushClient.SendNotification(subscription, "asd", options);

UPDATE
The conversion error is being thrown in Encryptor.cs:20 when trying to convert the keys. At this point the values I have are:

userKey: "p256ecdsa=BCvlec_uZKKZDzrf45jKLdAfLGBdKJZHjS7NsZt9GR-vW_iNF7mpbF-RKcq4nIbOeIkCYoDfG51njrtzFSTvT3E"

userSecret: "WebPush eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJodHRwczovL2ZjbS5nb29nbGVhcGlzLmNvbSIsImV4cCI6MTUyMzgwMTkyMSwic3ViIjoibWFpbHRvOmFzZGFzZEBnbWFpbC5jb20ifQ.gKkX9HnaFtm_D2nMK0xpmw4Hwu5L5xdhasSvTS4HHuDWXo4FM73ii6WQvYTb2VYYqnAEAgLUnfxWJWqukiMTuQ"

VAPID keys is nod valid

Method VapidHelper.GenerateVapidKeys() generates 66 byte long public key, while it must be 65 byte long

Bad Gateway 502

Hi!

I have an issues and a few questions in that regard. When using SendNotificationAsync() while sending around 5000 notifications sometime I get a WebPushException with http status code 502 Bad Gateway. Both from FCM and mozilla - i searched trough the documentation and could not find anything that useful. Does anybody know what I can do about it?
Is there a limit on the number of notifications they can process? But 5k seems not much to me.
Or is there a way to send notifications in a batch or should I better use SendNotification()?

As a side note I am on version 1.0.9 because with one of the newer versions a different System.Http version was targeted which I can not use - we use the one provided by the framework itself and ran into errors using version 1.0.11 of this library.

Thanks for any help!
Greetings, Julian

Edge 17

Would Edge 17 support it? If yes, please update "Browser support".

Include response content in WebPushException

When diagnosing WebPushException , it might be useful to include the body of the http response content received from google when calling the send rest API , as it might contain additional information , regarding cause of the error.

Inconsistent casing of gcmAPIKey in GenerateRequestDetails

The check is all caps, gcmAPIKey:

List<string> validOptionsKeys = new List<string> { "headers", "gcmAPIKey", "vapidDetails", "TTL" };

But usage is not, gcmApiKey:

if (options.ContainsKey("gcmApiKey"))
{
  string gcmApiKey = options["gcmApiKey"] as string;

Received unexpected response code

Hello i build table that collect all the data from the uesr , and i have user that the endpoint is :
fcm.googleapis.com
android.googleapis.com
i send bulk with alot of users but i sometime get this error(in the title )
most of the message that not sent is with endpoint: android.googleapis.com but i have some with fcm..
i dont know what to do i use for all 1 public and 1 privte key .. some one have any idea ?

{Method: POST, RequestUri: 'https://android.googleapis.com/gcm/send/cvwgJGuCqeQ:APA91bER_awcj_o6UtxAWEaDKSAVUwiAxRW3ld9l71EDrWxkeucUF3qxw7dG1HJxsml5uD_MGBXbHLgwSk-wSt-KRrulDTiNcfqACB7vsc4ClqkoXvyU1e7bZQ4l8rs9zMR30fOjPzhe', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:
{
TTL: 2419200
Encryption: salt=gH6AzKaQek5V1OIkrmTYNQ
Authorization: AIzaSyDIf4Dhgnmrdr0a855CQpsJaiuTueWboiw
Crypto-Key: dh=BAjgG0OwFLj9Pf-AYJKIBIsGjtY6Ag8xh7pAGlvftErf9oJk4268QnlpC-ucbo0HRNDgMkrkDW_mObxdlP3zAIE
Content-Type: application/octet-stream
Content-Length: 234
Content-Encoding: aesgcm
}}

UnauthorizedRegistration

Error 400

Improve HttpClient Usage

Hello!

I'm a big fan of this library, and I'm glad that there's a .NET solution for web push.

I was looking through the source code, and I noticed an easy to stumble into code smell in the SendNotification implementation: a new HttpClient is created for each notification sent.

There's a good article explaining why this is bad, and how to fix it.

Add strong name to assemby

It is impossible to use this library in strong named applications, because it does not have strong name.

Also, there are no sense to use netcoreapp1.0;netcoreapp1.1;netcoreapp2.0 as target frameworks, this frameworks are actual for applications not library. Better to use netstandard2.0 framework for dotnetcore and net46 for normal windows framework (without this target 'big' framework will use netstandard1.1 and lot of shims). So, all set of frameworks should be similar to this: netstandard1.1;netstandard2.0;net46

Send Message to All Users at once

Hello,
First of all thank you for your best library.
I wanted to send push notification to all users at once. But SendNotification method just gets 1 Subscription at a time. can you develope it to get list of Subscriptions ?

Include subscription in WebPushException

Hi!

This is more a feature request than an issue.
In the case that a stored subscription is not valid any more I get a WebPushException with status code "Gone", but at that moment I don't now to which subscription it relates to. So I'm not able to delete it from my database and will get this exception again and again. Therefore it would be great to provide the subscription via the WebPushException.
What you think about it?

Edit: I have troubles using Web Push with VAPID and payload on Firefox (v. 46.xx). On Chrome I receive the notification with data without any issues but when sending to Firefox I get a "NotFound" within a WebPushException. I tried to debug it, but there isn't any hint I could find. Do you/anybody have tips for that matter?

Thank you!

Http STATUS codeBadRequest

Hello i am try do to the backend only so i build this :
public void Index()
{

        var pushEndpoint = @"https://fcm.googleapis.com/fcm/send/fbS0D_DPY94:APA91bH8fSCblmu5MOFiwztvSnJ_3Q8d9fUpwpPV1PdGTrFGdn4C-vP129YGYchWT94-FcgURsRVjMjg9t81zSagBxqY0Zlh-XB0xSSqbMkJtHDzpP8EE8mKU_bO5rzNTM9WWP0-pC54";
        var p256dh = @"BMISWPIyfllGmT8bccStpEMlvv5yMt4Nv060JmAd61rJktxm1dQxcSaFiaSq-tWrA3upfNRia7T3ZRSh53GA4D0=";
        var auth = @"pZMkN3BD047pc5cT2HLQ2A==";

        var subject = @"mailto:[email protected]";
        var publicKey = @"BI8zZLNVYKSaymLdDp_mzo7_F4CIkJ2036r8AeZDt8DicO7oKXrnb9lngRRfwp-PrFRdg5KWS2LdAFTXZzSq58U";
        var privateKey = @"Q7bSuxP5XEYFk0P-bltzknpKq6irtjWdkm0h6VF9AGU";

        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.SendNotification(subscription, "payload", vapidDetails);
            //webPushClient.SendNotification(subscription, "payload", gcmAPIKey);
        }
        catch (WebPushException exception)
        {
            Response.Write("Http STATUS code" + exception.StatusCode);
        }

    }

but this says me the error .. what can be the problem ?

Not working with Asp.Net Core 2

I installed the 1.0.9 version from nugget in an asp.net core 2 project, but when i tried to send a push notification this exception happend:
TypeLoadException: Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Feature Request: Allow HttpClient to be provided for WebPushClient

Feature Request: would you consider changing WebPushClient so that the HttpClient could be provided either through the existing property or as a constructor argument? I would like to be able to provide my own HttpClient through DI as that would allow me to take advantage of other technologies (Ex: Polly) through DI. Thanks!

403 Forbidden

In some cases, I'm having a 403 Forbidden error

When debugging the probe is when I call
webPushClient.SendNotification (pushSubscription, finalMessage, vapidDetails);
Is there any way I can tell why some have this problem?
Does this have to do with the generation of the key and the subject in generation?
Error:

<properties>
  <property key="Objeto EX:">
    <structure type="WebPushException">
      <property key="StatusCode">Forbidden</property>
      <property key="Headers">
        <sequence>
          <item>
            <structure type="KeyValuePair`2">
              <property key="Key">X-Content-Type-Options</property>
              <property key="Value">
                <sequence>
                  <item>nosniff</item>
                </sequence>
              </property>
            </structure>
          </item>
          <item>
            <structure type="KeyValuePair`2">
              <property key="Key">X-Frame-Options</property>
              <property key="Value">
                <sequence>
                  <item>SAMEORIGIN</item>
                </sequence>
              </property>
            </structure>
          </item>
          <item>
            <structure type="KeyValuePair`2">
              <property key="Key">X-Xss-Protection</property>
              <property key="Value">
                <sequence>
                  <item>1; mode=block</item>
                </sequence>
              </property>
            </structure>
          </item>
          <item>
            <structure type="KeyValuePair`2">
              <property key="Key">Date</property>
              <property key="Value">
                <sequence>
                  <item>Tue, 04 Jun 2019 13:14:36 GMT</item>
                </sequence>
              </property>
            </structure>
          </item>
          <item>
            <structure type="KeyValuePair`2">
              <property key="Key">Alt-Svc</property>
              <property key="Value">
                <sequence>
                  <item>quic=":443"; ma=2592000; v="46,44,43,39"</item>
                </sequence>
              </property>
            </structure>
          </item>
        </sequence>
      </property>
      <property key="PushSubscription">
        <structure type="PushSubscription">
          <property key="Endpoint">https://fcm.googleapis.com/fcm/send/e4v4Q1....:AP9M......</property>
          <property key="P256DH">BDEIDL7KZs.......</property>
          <property key="Auth">WZIPE...........</property>
        </structure>
      </property>
      <property key="Message">Received unexpected response code: 403</property>
      <property key="Data" />
      <property key="InnerException" />
      <property key="TargetSite">Void HandleResponse(System.Net.Http.HttpResponseMessage, WebPush.PushSubscription)</property>
      <property key="StackTrace">   at WebPush.WebPushClient.HandleResponse(HttpResponseMessage response, PushSubscription subscription)
   at WebPush.WebPushClient.SendNotification(PushSubscription subscription, String payload, Dictionary`2 options)
   at COI.Nuntius.Services.PushService.EnviaPushNotification(Int32 DeviceId) in PushMensagem.cs:line 52</property>
      <property key="HelpLink" />
      <property key="Source">WebPush</property>
      <property key="HResult">-2146233088</property>
    </structure>
  </property>
  <property key="SetorErro">Nuntius</property>
</properties>

Indicating timeout for push request

Is there a plan to add timeout for the the HttpClient? i've noticed the WebPushClient constructor can receive an HttpClientHandler, unfortunately the timeout argument belong to the HttpClient itself which is private/protected.

(The motivation is of course to prevent hangs during SendNotification. I would use the Async method but that would mask the real send failures)

VAPID expiration

Hi!

What is VAPID expiration for? Is the key not valid after that time? Or is it the expiration of the push notification itself?
I found the following code within the GetVapidHeaders function in VapidHelper.cs:
if (expiration == -1) { expiration = UnixTimeNow() + 43200; }
Problem is that -1 is the default value for that function call and is called without a expiration. Therefore the default is always used. Is that behavior intended?

Thank you!

Wrong Exception...

Instead of throwing "AggregateException" which does not include the status codes, We/I expect to receive "WebPushException" and be able to handle each status code separately
Main Exception:
One or more errors occurred.

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)

at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at WebPush.WebPushClient.SendNotification(PushSubscription subscription, String payload, VapidDetails vapidDetails)
at TestServiceWorkerAndPush.WebPushService.DoNotify() in C:\Users\Hassan\Documents\Visual Studio 2015\Projects\TestServiceWorkerAndPush\TestServiceWorkerAndPush\WebPushService.cs:line 45

Inner Exception:
Received unexpected response code

at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at WebPush.WebPushClient.d__15.MoveNext()

Otherwise the sample code is wrong

Cannot send notification with expiration date

"WebPushClient.SendNotification" does not allow sending notification with expiration date.

Internally, it calls "VapidHelper.GetVapidHeaders" which has "expiration" parameter, but it is omitted and it defaults to 12 hours.

It would be nice if we could pass our own value somehow (perhaps through "VapidDetails" object?)

Or maybe there's a way to work around it which I did not find?
I'd be grateful for any help.

senderID MIsmatch and i tried testing with Subscription details

then i tried testing in webPush.Test and one more thing i am not using core
i am using .net framework and rest followed the way in webpush i am getting an error
public static EncryptionResult Encrypt(string userKey, string userSecret, string payload)
{
var userKeyBytes = UrlBase64.Decode(userKey);
var userSecretBytes = UrlBase64.Decode(userSecret);
var payloadBytes = Encoding.UTF8.GetBytes(payload);

        return Encrypt(userKeyBytes, userSecretBytes, payloadBytes);
    }

at end i am getting an error

System.IO.FileLoadException: 'Could not load file or assembly 'BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

that i have installed 1.8.5.0 vertion of portable.BouncyCastle

Using this library with UWP app "alternate channel"

Reference: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/alternate-channel-vapid-webpush

We've made a UWP app which calls the CreateRawPushNotificationChannelWithAlternateKeyForApplicationAsync API. This returns a endpoint URL which contains a token in the query string of the URL. No p256dh or auth parameters are returned by this API.

I'm unclear now how to proceed because every WebPush library, including this one, seems to require as a minimum the endpoint, p256dh and auth to form a complete "push subscription".

The documentation on the MSDN there, as you can see, is extremely vague!

I have generated a VAPID public+private key pair and that part seems fine. I am passing in the public key part of this into that CreateRawPushNotificationChannelWithAlternateKeyForApplicationAsync function as the appServerKey parameter. But am now unclear what to do in order to get the p256dh and auth parts which appear to be essential.

Any ideas/tips would be greatly appreciated! Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.