diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs
index c7b5676b7e30..b0315cf7b114 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventBinding.cs
@@ -248,10 +248,7 @@ internal static AuthenticationEventMetadata GetEventAndValidateSchema(string bod
{
try
{
- if (!Helpers.IsJson(body))
- {
- throw new RequestValidationException(AuthenticationEventResource.Ex_Invalid_JsonPayload);
- }
+ Helpers.ValidateJson(body);
}
catch (JsonException ex)
{
diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.Designer.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.Designer.cs
index b4f5496093b2..4a1cbc426aad 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.Designer.cs
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.Designer.cs
@@ -79,6 +79,15 @@ internal static string Ex_Context_Null {
}
}
+ ///
+ /// Looks up a localized string similar to JSON is null or empty..
+ ///
+ internal static string Ex_Empty_Json {
+ get {
+ return ResourceManager.GetString("Ex_Empty_Json", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Cannot determine the event from payload, please check that the incoming payload is a valid JSON string and contains the event type..
///
@@ -188,7 +197,7 @@ internal static string Ex_Invalid_Response {
}
///
- /// Looks up a localized string similar to Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return..
+ /// Looks up a localized string similar to Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.
///
internal static string Ex_Invalid_Return {
get {
diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.resx b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.resx
index d957f840d895..31fe2ad8dbd4 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.resx
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.resx
@@ -123,6 +123,9 @@
ListenerFactoryContext is null
+
+ JSON is null or empty.
+
Cannot determine the event from payload, please check that the incoming payload is a valid JSON string and contains the event type.
@@ -160,7 +163,7 @@
Response validation failed, see inner exceptions.
- Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.
+ Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function returnInvalid version on Schema
diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs
index 97f76bddd09e..7dd18e19f5c9 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs
@@ -227,10 +227,7 @@ internal static AuthenticationEventJsonElement GetJsonObjectFromString(string re
{
try
{
- if (!Helpers.IsJson(result))
- {
- throw new ResponseValidationException(AuthenticationEventResource.Ex_Invalid_Return);
- }
+ Helpers.ValidateJson(result);
}
catch (JsonException ex)
{
diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Helpers.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Helpers.cs
index 0bfcafc94b30..5d6c0949eeb6 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Helpers.cs
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Helpers.cs
@@ -108,19 +108,16 @@ internal static HttpResponseMessage HttpJsonResponse(AuthenticationEventJsonElem
/// Determines whether the specified input is json.
/// The input.
- ///
- /// true if the specified input is json; otherwise, false.
- internal static bool IsJson(string input)
+ internal static void ValidateJson(string input)
{
if (string.IsNullOrEmpty(input))
{
- return false;
+ throw new JsonException(AuthenticationEventResource.Ex_Empty_Json);
}
- // try parsing input to json object
- using var _ = JsonDocument.Parse(input);
- return true;
- }
+ // try parsing input to json object
+ using var _ = JsonDocument.Parse(input);
+ }
internal static AuthenticationEventAction GetEventActionForActionType(string actionType)
{
diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/AuthenticationEventBindingTests.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/AuthenticationEventBindingTests.cs
index ae13eda877ea..4dda66d0a13e 100644
--- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/AuthenticationEventBindingTests.cs
+++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/AuthenticationEventBindingTests.cs
@@ -33,7 +33,7 @@ private static IEnumerable