mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
[SG-419] Fix problems with push notifications on self-host (#2338)
* Added "internal" to non-user-based request types to avoid failing validation. * Added handling of unsuccessful response so that JSON parsing eror doesn't occur. * Added logging for token errors. (cherry picked from commit dad143b3e42247bc6b397b60803e25d243bd83a5) * Fixed bug in next auth attempt handling. * Fixed linting. * Added deserialization options to handle case insensitivity. * Added a new method for SendAsync that does not expect a result from the client. * hasJsonResult param to make Send more reusable * some cleanup * fix lint problems * Added launch config for Notifications. * Added Notifications to Full Server config. Co-authored-by: Kyle Spearrin <kyle.spearrin@gmail.com>
This commit is contained in:
@ -7,6 +7,9 @@ namespace Bit.Notifications;
|
||||
|
||||
public static class HubHelpers
|
||||
{
|
||||
private static JsonSerializerOptions _deserializerOptions =
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
||||
|
||||
public static async Task SendNotificationToHubAsync(
|
||||
string notificationJson,
|
||||
IHubContext<NotificationsHub> hubContext,
|
||||
@ -23,7 +26,7 @@ public static class HubHelpers
|
||||
case PushType.SyncLoginDelete:
|
||||
var cipherNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<SyncCipherPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
if (cipherNotification.Payload.UserId.HasValue)
|
||||
{
|
||||
await hubContext.Clients.User(cipherNotification.Payload.UserId.ToString())
|
||||
@ -41,7 +44,7 @@ public static class HubHelpers
|
||||
case PushType.SyncFolderDelete:
|
||||
var folderNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<SyncFolderPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
await hubContext.Clients.User(folderNotification.Payload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", folderNotification, cancellationToken);
|
||||
break;
|
||||
@ -52,7 +55,7 @@ public static class HubHelpers
|
||||
case PushType.LogOut:
|
||||
var userNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<UserPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
await hubContext.Clients.User(userNotification.Payload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", userNotification, cancellationToken);
|
||||
break;
|
||||
@ -61,21 +64,21 @@ public static class HubHelpers
|
||||
case PushType.SyncSendDelete:
|
||||
var sendNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<SyncSendPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
await hubContext.Clients.User(sendNotification.Payload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", sendNotification, cancellationToken);
|
||||
break;
|
||||
case PushType.AuthRequestResponse:
|
||||
var authRequestResponseNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<AuthRequestPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
await anonymousHubContext.Clients.Group(authRequestResponseNotification.Payload.Id.ToString())
|
||||
.SendAsync("AuthRequestResponseRecieved", authRequestResponseNotification, cancellationToken);
|
||||
break;
|
||||
case PushType.AuthRequest:
|
||||
var authRequestNotification =
|
||||
JsonSerializer.Deserialize<PushNotificationData<AuthRequestPushNotification>>(
|
||||
notificationJson);
|
||||
notificationJson, _deserializerOptions);
|
||||
await hubContext.Clients.User(authRequestNotification.Payload.UserId.ToString())
|
||||
.SendAsync("ReceiveMessage", authRequestNotification, cancellationToken);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user