public async Task <IActionResult> Subscription([FromBody] Lib.Net.Http.WebPush.PushSubscription subscription) { if (subscription != null && !string.IsNullOrEmpty(subscription.Endpoint)) { var tenantId = _tenantIdResolver.GetTenantId();; var existing = await _subscriptionStore.GetSubscriptionByEndpoint(tenantId, subscription.Endpoint); if (existing != null) { //the user could subscribe while not authenticated, if they are later authenticated add the userid to the subscription if (string.IsNullOrEmpty(existing.UserId) && User.Identity.IsAuthenticated) { existing.UserId = _userIdResolver.GetCurrentUserId(); await _subscriptionStore.UpdateSubscription(existing); } } else { var newSub = new PushDeviceSubscription(subscription); newSub.TenantId = _tenantIdResolver.GetTenantId(); newSub.UserId = _userIdResolver.GetCurrentUserId(); newSub.UserAgent = Request.Headers["User-Agent"].ToString(); newSub.CreatedFromIpAddress = HttpContext.Connection.RemoteIpAddress.ToString(); await _subscriptionStore.CreateSubscription(newSub); } } return(NoContent()); }
public IActionResult SubscribeClient([FromBody] Lib.Net.Http.WebPush.PushSubscription subscription) { //validazione argomenti if (subscription == null) { return(BadRequest($"{nameof(subscription)} cannot be null")); } //aggiunta sottoscrizione a registro applicazione SubscriptionsPersistence.Subscriptions.Add(subscription); //risultato operazione return(Ok(true)); }
public PushDeviceSubscription(Lib.Net.Http.WebPush.PushSubscription subscription) { Key = Guid.NewGuid(); Endpoint = subscription.Endpoint; Keys = subscription.Keys; }