Entra.EventHandlers.AzureFunctions 1.2.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Entra.EventHandlers.AzureFunctions --version 1.2.4
                    
NuGet\Install-Package Entra.EventHandlers.AzureFunctions -Version 1.2.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Entra.EventHandlers.AzureFunctions" Version="1.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Entra.EventHandlers.AzureFunctions" Version="1.2.4" />
                    
Directory.Packages.props
<PackageReference Include="Entra.EventHandlers.AzureFunctions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Entra.EventHandlers.AzureFunctions --version 1.2.4
                    
#r "nuget: Entra.EventHandlers.AzureFunctions, 1.2.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Entra.EventHandlers.AzureFunctions@1.2.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Entra.EventHandlers.AzureFunctions&version=1.2.4
                    
Install as a Cake Addin
#tool nuget:?package=Entra.EventHandlers.AzureFunctions&version=1.2.4
                    
Install as a Cake Tool

Entra.EventHandlers.AzureFunctions

Azure Functions hosting adapter for Microsoft Entra External ID Authentication Event Handlers.
Provides minimal‑boilerplate hosting, full DI support, structured error handling, and complete testability.

License: Business Source License (BSL)
Author: Jakub Szubarga (Szubarga.NET)


✨ Features

  • 🚀 Single Function → Multiple Entra Event Types
  • 🔄 Automatic request deserialization & response serialization
  • 🧩 Dynamic handler resolution via DI
  • 🛡 Structured error mapping (400/500)
  • 🧪 Fully unit‑testable (no static calls, no real HTTP streams)
  • 🪶 Minimal boilerplate

🧠 Core Router

public abstract class EntraEventRouterFunctionBase(
    ILogger<EntraEventRouterFunctionBase> logger,
    IEntraEventHandlerResolver resolver,
    IHttpRequestAdapter requestAdapter,
    IHttpResponseAdapter responseAdapter)
{
    private readonly ILogger<EntraEventRouterFunctionBase> _logger = logger;
    private readonly IEntraEventHandlerResolver _resolver = resolver;
    private readonly IHttpRequestAdapter _requestAdapter = requestAdapter;
    private readonly IHttpResponseAdapter _responseAdapter = responseAdapter;

    protected async Task<HttpResponseData> Run(HttpRequestData req, FunctionContext context)
    {
        try
        {
            var evt = await _requestAdapter.ReadEvent(req);
            var handler = _resolver.Resolve(evt.GetType());

            var response = await ((dynamic)handler).Handle((dynamic)evt, context.CancellationToken);
            return await _responseAdapter.From(req, response);
        }
        catch (Exception ex) when (ex is EntraValidationException or EntraDeserializationException or EntraHandlerNotFoundException)
        {
            _logger.LogWarning(ex, "Handled expected Entra exception.");

            var code = ex switch
            {
                EntraValidationException => EntraErrorCodes.ValidationError,
                EntraDeserializationException => EntraErrorCodes.DeserializationError,
                EntraHandlerNotFoundException => EntraErrorCodes.HandlerNotFound,
                _ => throw new InvalidOperationException("Unreachable: catch filter guarantees only known Entra exceptions.")
            };

            return await _responseAdapter.BadRequest(
                req,
                new EntraErrorResponse
                {
                    Error = code,
                    Details = ex.Message
                });
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Unhandled exception while processing Entra event.");

            return await _responseAdapter.ServerError(
                req,
                new EntraErrorResponse
                {
                    Error = EntraErrorCodes.UnhandledException,
                    Details = "An unexpected error occurred."
                });
        }
    }
}

🧩 Minimal Azure Function

public sealed class EntraRouterFunction : EntraEventRouterFunctionBase
{
    public EntraRouterFunction(
        ILogger<EntraEventRouterFunctionBase> logger,
        IEntraEventHandlerResolver resolver,
        IHttpRequestAdapter requestAdapter,
        IHttpResponseAdapter responseAdapter)
        : base(logger, resolver, requestAdapter, responseAdapter) {}

    [Function("EntraRouter")]
    public Task<HttpResponseData> RunAsync(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
        FunctionContext ctx)
        => Run(req, ctx);
}

🛠 Dependency Injection

public static class EntraEventHandlersFunctionExtensions
{
    public static IServiceCollection AddEntraEventHandlersForFunctions(this IServiceCollection services)
    {
        services.AddSingleton<IHttpRequestAdapter, HttpRequestAdapter>();
        services.AddSingleton<IHttpResponseAdapter, HttpResponseAdapter>();
        services.AddSingleton<IEntraEventHandlerResolver, EntraEventHandlerResolver>();

        services.Scan(scan => scan
            .FromApplicationDependencies()
            .AddClasses(c => c.AssignableTo(typeof(IEntraEventHandler<,>)))
            .AsImplementedInterfaces()
            .WithTransientLifetime());

        return services;
    }
}

🧪 Unit Testing Example

[Fact]
public async Task Run_WhenDeserializationFails_ReturnsBadRequest()
{
    // Arrange
    var ctx = Substitute.For<FunctionContext>();
    var request = Substitute.For<HttpRequestData>(ctx);
    var response = Substitute.For<HttpResponseData>(ctx);

    var exception = new EntraDeserializationException("bad");
    _requestAdapter.ReadEvent(request).Throws(exception);

    _responseAdapter
        .BadRequest(request, Arg.Any<EntraErrorResponse>())
        .Returns(response);

    // Act
    var result = await _sut.RunAsync(request, ctx);

    // Assert
    _responseAdapter.Received(1).BadRequest(
        request,
        Arg.Is<EntraErrorResponse>(e =>
            e.Error == EntraErrorCodes.DeserializationError &&
            e.Details == "bad"));

    _logger.Entries.Should().ContainSingle(e =>
        e.Level == LogLevel.Warning &&
        e.Exception == exception);
}

📦 Optional: Single‑Event Base Classes

public abstract class TokenIssuanceStartFunctionBase(
    ITokenIssuanceStartHandler handler,
    IHttpRequestAdapter requestAdapter,
    IHttpResponseAdapter responseAdapter)
{
    private readonly ITokenIssuanceStartHandler _handler = handler;
    private readonly IHttpRequestAdapter _requestAdapter = requestAdapter;
    private readonly IHttpResponseAdapter _responseAdapter = responseAdapter;

    protected async Task<HttpResponseData> Run(HttpRequestData req, FunctionContext context)
    {
        var evt = await _requestAdapter.ReadEvent<TokenIssuanceStartEvent>(req);
        var response = await _handler.Handle(evt, context.CancellationToken);
        return await _responseAdapter.From(req, response);
    }
}

🔒 License

This package is licensed under the Business Source License (BSL).

A commercial license is required for production use by organizations with more than 5 employees.

Pricing

  • Developer License — €99 / developer / year
  • Team License — €399 / year
  • Enterprise License — €1499 / year

📧 jakub.szubarga@gmail.com

The abstractions package is MIT‑licensed and can be used freely.


📚 Documentation

Full documentation, examples, and production templates will be available in the main repository as the ecosystem evolves.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 42 6/11/2026
1.2.9 79 6/8/2026
1.2.8 79 6/8/2026
1.2.7 125 6/7/2026
1.2.6 92 6/6/2026
1.2.5 81 6/6/2026
1.2.4 92 6/5/2026
1.2.3 121 6/3/2026
1.2.0 109 6/3/2026

Initial release of Azure Functions hosting adapter for Entra Event Handlers.