Example #1
0
        public IActionResult UnSubscribe([FromBody] WebPushModel subscriptionModel)
        {
            var subscriptionToDelete = Get(subscriptionModel.EndPoint, subscriptionModel.P256dH, subscriptionModel.Auth);

            if (subscriptionToDelete != null)
            {
                _context.WebPushSubscriptions.Remove(subscriptionToDelete);
                _context.SaveChanges();
                return(Ok(subscriptionToDelete));
            }

            return(Ok());
        }
Example #2
0
        public IActionResult Subscribe([FromBody] WebPushModel subscriptionModel)
        {
            var newSubscription = new WebPushSubscription
            {
                Auth     = subscriptionModel.Auth,
                EndPoint = subscriptionModel.EndPoint,
                P256dH   = subscriptionModel.P256dH
            };

            _context.WebPushSubscriptions.Add(newSubscription);
            _context.SaveChanges();
            return(Ok(newSubscription));
        }
Example #3
0
        public async Task <IActionResult> PostWebPushAsync([FromBody] WebPushModel webPushModel, CancellationToken cancellationToken = default)
        {
            synker.entities.Notifications.Device device = await _dbContext.Devices.FirstOrDefaultAsync(x => x.Id == webPushModel.Id, cancellationToken);

            if (device == null)
            {
                return(NotFound(device));
            }

            PushSubscription pushSubscription = new PushSubscription(device.PushEndpoint, device.PushP256DH, device.PushAuth);
            VapidDetails     vapidDetails     = new VapidDetails("mailto:[email protected]", _vapidKeysConfig.PublicKey, _vapidKeysConfig.PrivateKey);

            new WebPushClient().SendNotification(pushSubscription, webPushModel.Payload, vapidDetails);
            return(Ok());
        }