Entra.EventHandlers.Security
1.0.3
See the version list below for details.
dotnet add package Entra.EventHandlers.Security --version 1.0.3
NuGet\Install-Package Entra.EventHandlers.Security -Version 1.0.3
<PackageReference Include="Entra.EventHandlers.Security" Version="1.0.3" />
<PackageVersion Include="Entra.EventHandlers.Security" Version="1.0.3" />
<PackageReference Include="Entra.EventHandlers.Security" />
paket add Entra.EventHandlers.Security --version 1.0.3
#r "nuget: Entra.EventHandlers.Security, 1.0.3"
#:package Entra.EventHandlers.Security@1.0.3
#addin nuget:?package=Entra.EventHandlers.Security&version=1.0.3
#tool nuget:?package=Entra.EventHandlers.Security&version=1.0.3
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:
- Microsoft Entra sends an encrypted password context.
- The base handler decrypts the payload.
- Business logic receives a strongly typed
DecryptedPasswordContext. - The password is validated against a legacy identity store.
- 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
Related Packages
| 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 | Versions 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. |
-
net10.0
- Azure.Identity (>= 1.21.0)
- Azure.Security.KeyVault.Secrets (>= 4.11.2)
- Entra.EventHandlers.Abstractions (>= 1.6.0)
- jose-jwt (>= 5.3.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Options (>= 10.0.14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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.