diff --git a/src/Api/Api.csproj b/src/Api/Api.csproj index a587328913..f02d00718b 100644 --- a/src/Api/Api.csproj +++ b/src/Api/Api.csproj @@ -28,10 +28,10 @@ + - diff --git a/src/Api/Controllers/CiphersController.cs b/src/Api/Controllers/CiphersController.cs index b19f4f453d..5a982418c6 100644 --- a/src/Api/Controllers/CiphersController.cs +++ b/src/Api/Controllers/CiphersController.cs @@ -14,7 +14,7 @@ using System.Collections.Generic; using Bit.Core.Models.Table; using Bit.Core.Settings; using Core.Models.Data; -using Microsoft.Azure.EventGrid.Models; +using Azure.Messaging.EventGrid; using Bit.Core.Models.Data; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/src/Api/Controllers/SendsController.cs b/src/Api/Controllers/SendsController.cs index f8f1689215..16d6c2d86b 100644 --- a/src/Api/Controllers/SendsController.cs +++ b/src/Api/Controllers/SendsController.cs @@ -12,7 +12,7 @@ using Bit.Core.Settings; using Bit.Core.Models.Api.Response; using Bit.Core.Enums; using Bit.Core.Context; -using Microsoft.Azure.EventGrid.Models; +using Azure.Messaging.EventGrid; using Bit.Api.Utilities; using System.Collections.Generic; using Bit.Core.Models.Table; diff --git a/src/Api/Utilities/ApiHelpers.cs b/src/Api/Utilities/ApiHelpers.cs index 83677bf8e0..4076b8e784 100644 --- a/src/Api/Utilities/ApiHelpers.cs +++ b/src/Api/Utilities/ApiHelpers.cs @@ -1,8 +1,8 @@ using Bit.Core.Utilities; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.EventGrid; -using Microsoft.Azure.EventGrid.Models; +using Azure.Messaging.EventGrid; +using Azure.Messaging.EventGrid.SystemEvents; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -55,29 +55,25 @@ namespace Bit.Api.Utilities } var response = string.Empty; - var requestContent = await new StreamReader(request.Body).ReadToEndAsync(); - if (string.IsNullOrWhiteSpace(requestContent)) - { - return new OkObjectResult(response); - } - - var eventGridSubscriber = new EventGridSubscriber(); - var eventGridEvents = eventGridSubscriber.DeserializeEventGridEvents(requestContent); - + var requestData = await BinaryData.FromStreamAsync(request.Body); + var eventGridEvents = EventGridEvent.ParseMany(requestData); foreach (var eventGridEvent in eventGridEvents) { - if (eventGridEvent.Data is SubscriptionValidationEventData eventData) + if (eventGridEvent.TryGetSystemEventData(out object systemEvent)) { - // Might want to enable additional validation: subject, topic etc. - - var responseData = new SubscriptionValidationResponse() + if (systemEvent is SubscriptionValidationEventData eventData) { - ValidationResponse = eventData.ValidationCode - }; + // Might want to enable additional validation: subject, topic etc. + var responseData = new SubscriptionValidationResponse() + { + ValidationResponse = eventData.ValidationCode + }; - return new OkObjectResult(responseData); + return new OkObjectResult(responseData); + } } - else if (eventTypeHandlers.ContainsKey(eventGridEvent.EventType)) + + if (eventTypeHandlers.ContainsKey(eventGridEvent.EventType)) { await eventTypeHandlers[eventGridEvent.EventType](eventGridEvent); }