Entra.EventHandlers.Security 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Entra.EventHandlers.Security --version 1.0.2
                    
NuGet\Install-Package Entra.EventHandlers.Security -Version 1.0.2
                    
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.Security" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Entra.EventHandlers.Security" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Entra.EventHandlers.Security" />
                    
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.Security --version 1.0.2
                    
#r "nuget: Entra.EventHandlers.Security, 1.0.2"
                    
#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.Security@1.0.2
                    
#: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.Security&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Entra.EventHandlers.Security&version=1.0.2
                    
Install as a Cake Tool

Entra.EventHandlers.Security

Security extensions for Microsoft Entra External ID authentication event handlers.

This package provides production-ready components for handling security-sensitive scenarios in the Entra.EventHandlers ecosystem, including PasswordSubmit payload decryption using certificates stored in Azure Key Vault.

Installation

dotnet add package Entra.EventHandlers.Security

Why This Package Exists

The Microsoft Entra External ID PasswordSubmit event sends the user's password inside an encrypted password context.

Decrypting this payload requires:

  • Secure certificate management
  • RSA private key extraction
  • JWE/JWT decryption
  • Payload deserialization
  • Payload validation
  • Secure cryptographic handling

This package provides production-ready implementations for these requirements.

Most applications using PasswordSubmit never need to manually decrypt the payload.

When using PasswordSubmitHandlerBase, the encrypted password context is automatically decrypted and provided as a strongly typed DecryptedPasswordContext instance.


Features

Password Context Decryption

Decrypt encrypted password contexts received during the PasswordSubmit event.

Primary interface:

IPasswordContextDecryptor

Provided implementation:

KeyVaultPasswordContextDecryptor

Azure Key Vault Certificate Integration

Load certificates stored in Azure Key Vault.

Primary interface:

IKeyVaultCertificateProvider

Provided implementation:

KeyVaultCertificateProvider

Dependency Injection Integration

Simple registration using standard .NET dependency injection.

builder.Services.AddEntraEventHandlersSecurity();

Secure RSA Key Caching

The RSA private key is:

  • Loaded only once
  • Cached in memory
  • Reused across requests
  • Protected by thread-safe initialization

This minimizes Azure Key Vault traffic and reduces request latency.


Supported Scenario

This package currently focuses on the Microsoft Entra External ID:

PasswordSubmit

custom authentication extension event.

Typical flow:

Microsoft Entra
        │
        ▼
PasswordSubmit Event
        │
        ▼
EncryptedPasswordContext
        │
        ▼
Azure Key Vault Certificate
        │
        ▼
RSA Private Key
        │
        ▼
DecryptedPasswordContext
        │
        ▼
Password Validation
        │
        ▼
Password Migration

Configuration

Configure access to the Azure Key Vault certificate.

{
  "KeyVault": {
    "VaultUrl": "https://contoso.vault.azure.net/",
    "CertificateName": "password-submit-certificate"
  }
}

Register configuration:

builder.Services.Configure<KeyVaultCertificateOptions>(
    builder.Configuration.GetSection(
        KeyVaultCertificateOptions.SectionName));

Register security services:

builder.Services.AddEntraEventHandlersSecurity();

PasswordSubmit Integration

The primary use case for this package is the PasswordSubmit event.

The security package integrates directly with:

PasswordSubmitHandlerBase

Once an IPasswordContextDecryptor implementation is supplied, the encrypted password context is automatically decrypted before your business logic executes.

Example:

public class PasswordSubmitHandler(
    ILogger<PasswordSubmitHandler> logger,
    IPasswordContextDecryptor decryptor)
    : PasswordSubmitHandlerBase(logger, decryptor)
{
    protected override Task<PasswordSubmitResponse> HandleCoreAsync(
        PasswordSubmitEvent request,
        DecryptedPasswordContext decrypted,
        CancellationToken cancellationToken = default)
    {
        return Task.FromResult(
            EntraEventResponses
                .PasswordSubmit()
                .WithNonce(decrypted.Nonce)
                .MigratePassword()
                .Build());
    }
}

The handler receives a fully validated:

DecryptedPasswordContext

without any manual decryption code.

The base handler automatically:

  • Validates the request
  • Decrypts the encrypted password context
  • Validates the decrypted payload
  • Handles structured logging
  • Creates correlation scopes
  • Preserves the nonce
  • Generates safe responses when failures occur

Decrypted Password Context

The decrypted payload is represented by:

public sealed class DecryptedPasswordContext
{
    public string Password { get; init; }

    public string Nonce { get; init; }

    public string? Username { get; init; }
}

Properties:

Property Description
Password Plaintext password submitted by the user
Nonce Protocol nonce provided by Microsoft Entra
Username Optional username associated with the password

Example:

var username = decrypted.Username;
var password = decrypted.Password;
var nonce = decrypted.Nonce;

Values are validated before being returned to your handler.


Azure Key Vault Certificate Provider

The package includes a certificate provider that retrieves PKCS#12 certificates from Azure Key Vault and extracts RSA private keys.

Primary interface:

IKeyVaultCertificateProvider

Implementation:

KeyVaultCertificateProvider

Features:

  • Azure Key Vault integration
  • Certificate loading
  • RSA key extraction
  • In-memory caching
  • Thread-safe initialization
  • Structured logging

The RSA private key is extracted only once and reused across requests.


Example

Validate credentials against a legacy identity store.

public class PasswordSubmitHandler(
    ILogger<PasswordSubmitHandler> logger,
    IPasswordContextDecryptor decryptor)
    : PasswordSubmitHandlerBase(logger, decryptor)
{
    protected override async Task<PasswordSubmitResponse> HandleCoreAsync(
        PasswordSubmitEvent request,
        DecryptedPasswordContext decrypted,
        CancellationToken cancellationToken = default)
    {
        var validCredentials =
            await ValidateCredentialsAsync(
                decrypted.Username,
                decrypted.Password);

        return validCredentials
            ? EntraEventResponses
                .PasswordSubmit()
                .WithNonce(decrypted.Nonce)
                .MigratePassword()
                .Build()
            : EntraEventResponses
                .PasswordSubmit()
                .WithNonce(decrypted.Nonce)
                .Block()
                .Build();
    }
}

In this example:

  1. Microsoft Entra sends an encrypted password context.
  2. The base handler decrypts the payload.
  3. Business logic receives a strongly typed DecryptedPasswordContext.
  4. The password is validated against a legacy identity store.
  5. A migration or block response is returned.

Security Considerations

Never Log Passwords

Avoid:

_logger.LogInformation(
    "Password: {Password}",
    decrypted.Password);

Passwords should never be logged.


Never Persist Passwords

Avoid storing decrypted passwords in:

  • Databases
  • Logs
  • Telemetry systems
  • Distributed caches

Passwords should exist only for the duration of the request.


Always Return the Nonce

PasswordSubmit responses must include:

.WithNonce(decrypted.Nonce)

The nonce is required by the Microsoft Entra protocol.


Prefer Azure Key Vault

Store PasswordSubmit certificates in Azure Key Vault whenever possible.

Benefits include:

  • Centralized management
  • Managed Identity integration
  • Certificate rotation
  • Improved operational security

Documentation

Full documentation, event guides, hosting guides, testing guidance, security guidance, and samples:

https://github.com/szubajak/entra-event-handlers/tree/main/docs

Microsoft Entra External ID authentication event handlers documentation:

https://github.com/szubajak/entra-event-handlers/tree/main/docs/events

AI-friendly repository metadata:

https://github.com/szubajak/entra-event-handlers/blob/main/llms.txt


Package Purpose
Entra.EventHandlers.Abstractions Public contracts and protocol models
Entra.EventHandlers External ID implementation layer
Entra.EventHandlers.Workforce Workforce implementation layer
Entra.EventHandlers.AspNetCore ASP.NET Core hosting
Entra.EventHandlers.AzureFunctions Azure Functions hosting

License

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

The Entra.EventHandlers.Abstractions package is licensed under MIT and may be used freely.

See the repository for licensing details and commercial licensing information.


Further Reading

Microsoft Entra External ID Just-In-Time Password Migration

https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-migrate-passwords-just-in-time

Entra External ID .NET Handlers Deep Dive

https://medium.com/@jakub.szubarga/entra-external-id-dotnet-handlers-a7447dc1e437

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.1.0 120 11/16/2026
1.0.5 125 11/2/2026
1.0.4 141 10/27/2026
1.0.3 114 10/26/2026
1.0.2 116 10/25/2026
1.0.1 173 10/14/2026
1.0.0 135 10/9/2026

Provides PasswordSubmit encryptedPasswordContext decryption,
Azure Key Vault certificate integration, RSA private key extraction,
certificate caching, and production-ready implementations of
IPasswordContextDecryptor for Microsoft Entra External ID
Just-In-Time password migration scenarios.