From c08e2a747367749eb897082ddd70f867bafe307f Mon Sep 17 00:00:00 2001 From: Todd Martin <106564991+trmartin4@users.noreply.github.com> Date: Wed, 31 May 2023 11:12:43 -0400 Subject: [PATCH] Allow self-hosted notifications to work for Login with Device approval (#2934) * Added anonymous hub context. * Added anonymous hub to nginx setup. * Added deserialization options to ignore case on deserialization. --- docker-unified/hbs/nginx-config.hbs | 7 +++++++ src/Notifications/Controllers/SendController.cs | 6 ++++-- src/Notifications/HubHelpers.cs | 2 +- util/Setup/Templates/NginxConfig.hbs | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docker-unified/hbs/nginx-config.hbs b/docker-unified/hbs/nginx-config.hbs index 5b57673f1c..2e998d878f 100644 --- a/docker-unified/hbs/nginx-config.hbs +++ b/docker-unified/hbs/nginx-config.hbs @@ -134,6 +134,13 @@ server { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; } + + location /notifications/anonymous-hub { + proxy_pass http://localhost:5006/anonymous-hub; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $http_connection; + } + {{/if}} {{#if (String.Equal env.BW_ENABLE_EVENTS "true")}} diff --git a/src/Notifications/Controllers/SendController.cs b/src/Notifications/Controllers/SendController.cs index 247036a646..a5780517eb 100644 --- a/src/Notifications/Controllers/SendController.cs +++ b/src/Notifications/Controllers/SendController.cs @@ -10,10 +10,12 @@ namespace Bit.Notifications; public class SendController : Controller { private readonly IHubContext _hubContext; + private readonly IHubContext _anonymousHubContext; - public SendController(IHubContext hubContext) + public SendController(IHubContext hubContext, IHubContext anonymousHubContext) { _hubContext = hubContext; + _anonymousHubContext = anonymousHubContext; } [HttpPost("~/send")] @@ -25,7 +27,7 @@ public class SendController : Controller var notificationJson = await reader.ReadToEndAsync(); if (!string.IsNullOrWhiteSpace(notificationJson)) { - await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext, null); + await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext, _anonymousHubContext); } } } diff --git a/src/Notifications/HubHelpers.cs b/src/Notifications/HubHelpers.cs index 8da27f5a5f..71319dd559 100644 --- a/src/Notifications/HubHelpers.cs +++ b/src/Notifications/HubHelpers.cs @@ -17,7 +17,7 @@ public static class HubHelpers CancellationToken cancellationToken = default(CancellationToken) ) { - var notification = JsonSerializer.Deserialize>(notificationJson); + var notification = JsonSerializer.Deserialize>(notificationJson, _deserializerOptions); switch (notification.Type) { case PushType.SyncCipherUpdate: diff --git a/util/Setup/Templates/NginxConfig.hbs b/util/Setup/Templates/NginxConfig.hbs index e708ae7b0e..115c79c72a 100644 --- a/util/Setup/Templates/NginxConfig.hbs +++ b/util/Setup/Templates/NginxConfig.hbs @@ -132,6 +132,12 @@ server { proxy_set_header Connection $http_connection; } + location /notifications/anonymous-hub { + proxy_pass http://notifications:5000/anonymous-hub; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $http_connection; + } + location /events/ { proxy_pass http://events:5000/; }