Browse Source

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.
pull/2991/head
Todd Martin 3 years ago committed by GitHub
parent
commit
c08e2a7473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      docker-unified/hbs/nginx-config.hbs
  2. 6
      src/Notifications/Controllers/SendController.cs
  3. 2
      src/Notifications/HubHelpers.cs
  4. 6
      util/Setup/Templates/NginxConfig.hbs

7
docker-unified/hbs/nginx-config.hbs

@ -134,6 +134,13 @@ server { @@ -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")}}

6
src/Notifications/Controllers/SendController.cs

@ -10,10 +10,12 @@ namespace Bit.Notifications; @@ -10,10 +10,12 @@ namespace Bit.Notifications;
public class SendController : Controller
{
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly IHubContext<AnonymousNotificationsHub> _anonymousHubContext;
public SendController(IHubContext<NotificationsHub> hubContext)
public SendController(IHubContext<NotificationsHub> hubContext, IHubContext<AnonymousNotificationsHub> anonymousHubContext)
{
_hubContext = hubContext;
_anonymousHubContext = anonymousHubContext;
}
[HttpPost("~/send")]
@ -25,7 +27,7 @@ public class SendController : Controller @@ -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);
}
}
}

2
src/Notifications/HubHelpers.cs

@ -17,7 +17,7 @@ public static class HubHelpers @@ -17,7 +17,7 @@ public static class HubHelpers
CancellationToken cancellationToken = default(CancellationToken)
)
{
var notification = JsonSerializer.Deserialize<PushNotificationData<object>>(notificationJson);
var notification = JsonSerializer.Deserialize<PushNotificationData<object>>(notificationJson, _deserializerOptions);
switch (notification.Type)
{
case PushType.SyncCipherUpdate:

6
util/Setup/Templates/NginxConfig.hbs

@ -132,6 +132,12 @@ server { @@ -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/;
}

Loading…
Cancel
Save