CasCap.Api.Azure.Auth 1.7.0

Prefix Reserved
dotnet add package CasCap.Api.Azure.Auth --version 1.7.0
                    
NuGet\Install-Package CasCap.Api.Azure.Auth -Version 1.7.0
                    
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="CasCap.Api.Azure.Auth" Version="1.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CasCap.Api.Azure.Auth" Version="1.7.0" />
                    
Directory.Packages.props
<PackageReference Include="CasCap.Api.Azure.Auth" />
                    
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 CasCap.Api.Azure.Auth --version 1.7.0
                    
#r "nuget: CasCap.Api.Azure.Auth, 1.7.0"
                    
#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 CasCap.Api.Azure.Auth@1.7.0
                    
#: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=CasCap.Api.Azure.Auth&version=1.7.0
                    
Install as a Cake Addin
#tool nuget:?package=CasCap.Api.Azure.Auth&version=1.7.0
                    
Install as a Cake Tool

CasCap.Api.Azure.Auth

Azure credential helpers for .NET applications using client certificates or Kubernetes workload identity. The package also supplies an HTTP bearer handler and optional certificate-authentication registration for an Agent Runtime client.

Installation

Targets net8.0, net9.0 and net10.0.

dotnet add package CasCap.Api.Azure.Auth

Usage

Bind the application's configuration to AzureAuthConfig, then explicitly decide whether to use Key Vault before resolving a credential:

using CasCap.Models;
using Microsoft.Extensions.Configuration;

var auth = configuration.GetSection(AzureAuthConfig.ConfigurationSectionName)
    .Get<AzureAuthConfig>()
    ?? throw new InvalidOperationException("Configure AppConfig.");

if (auth.IsKeyVaultEnabled)
{
    var credential = auth.TokenCredential
        ?? throw new InvalidOperationException("Configure an Azure identity.");
    // Pass credential to an Azure SDK client or a Key Vault configuration provider.
}

AzureAuthConfig implements IAppConfig and IAzureAuthConfig. Its TokenCredential property lazily calls TokenCredentialExtensions.CreateTokenCredential. This package does not install a Key Vault configuration provider or automatically grant access to Azure resources.

Configuration Examples

Minimal configuration for an application that deliberately does not use Key Vault:

{
  "AppConfig": {
    "KeyVaultName": "skip"
  }
}

"skip" is case-insensitive and makes IsKeyVaultEnabled false. The caller must check that flag: reading TokenCredential directly still invokes the factory, even when Key Vault is disabled. Supply other secrets through user secrets, environment variables or a secret-backed provider.

Certificate authentication uses the same section:

{
  "AppConfig": {
    "KeyVaultName": "your-vault-name",
    "AzureEntraTenantId": "00000000-0000-0000-0000-000000000000",
    "AzureEntraApplicationId": "00000000-0000-0000-0000-000000000000",
    "AzureEntraPemPath": "C:\\credentials\\client.pem"
  }
}

Replace placeholders through private configuration. Configure exactly one certificate source:

Property Source
AzureEntraCertThumbprint Current user's Personal certificate store (CurrentUser\My)
AzureEntraPemPath One combined PEM file containing the certificate and private key
AzureEntraPfxPath PKCS#12/PFX file; optional password in AzureEntraPfxPassword

Multiple sources cause an exception rather than fallback selection. A missing matching certificate or no configured source returns null; a loaded certificate without tenant/application IDs throws. Upload the corresponding public certificate to the Entra application and grant that identity the required resource permissions. Protect private keys, passwords, cache/state and local paths; never commit them.

For workstation use, install the certificate with its private key in the current user's store and keep the thumbprint in the consuming application's user secrets. Remove deployment-only PEM/PFX settings from local providers so they do not conflict with the thumbprint.

Workload Identity

The factory selects WorkloadIdentityCredential when all four environment variables are present: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE and AZURE_AUTHORITY_HOST. It checks presence, not whether the values are valid.

Workload identity takes priority over certificate settings. AzureEntraPodManagedIdentityClientId optionally overrides the injected client ID. The cluster's identity federation and resource permissions must already be configured; this package does not provision them.

HTTP Client Authentication

TokenCredentialBearerHandler requests tokens for its supplied scopes and preserves an existing caller-owned Authorization header. AddAgentRuntimeAzureAuthentication(configuration) binds CasCap:AgentRuntimeAzureAuthConfig on an IHttpClientBuilder and adds the handler only when enabled:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

services.AddSingleton<IConfiguration>(configuration);
services.AddHttpClient("runtime")
    .AddAgentRuntimeAzureAuthentication(configuration);

Use the same registered IConfiguration for options binding. The extension reads its argument once to decide whether to add the handler; changing Enabled later does not rebuild that registration.

The minimal configuration leaves authentication disabled:

{
  "CasCap": {
    "AgentRuntimeAzureAuthConfig": {
      "Enabled": false
    }
  }
}

An enabled configuration requires a separate identity and API scope:

{
  "CasCap": {
    "AgentRuntimeAzureAuthConfig": {
      "Enabled": true,
      "TenantId": "00000000-0000-0000-0000-000000000000",
      "ClientId": "00000000-0000-0000-0000-000000000000",
      "Certificate": "your-combined-pem-certificate-and-private-key",
      "Scope": "api://00000000-0000-0000-0000-000000000000/.default"
    }
  }
}

Certificate is PEM content, not a file path. Supply real content from a secret provider. GetTokenCredential() creates the certificate credential lazily; validation requires the identity, certificate and scope when enabled. These options are separate from AppConfig.

Data Flow

Certificate sources are alternatives, while detected workload identity takes priority:

flowchart LR
    ENV{"Workload identity environment present?"}
    ENV -->|Yes| WI["WorkloadIdentityCredential"]
    ENV -->|No| CERT["Exactly one certificate source"]
    CERT --> STORE["CurrentUser certificate store"]
    CERT --> PEM["Combined PEM"]
    CERT --> PFX["PFX"]
    STORE --> CC["ClientCertificateCredential"]
    PEM --> CC
    PFX --> CC
    WI --> SDK["Azure SDK clients"]
    CC --> SDK
    classDef credential fill:#dbeafe,stroke:#2563eb,color:#111827
    class WI,CC credential

The same selection is described above for readers whose registry does not render Mermaid.

Documentation

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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 (5)

Showing the top 5 NuGet packages that depend on CasCap.Api.Azure.Auth:

Package Downloads
CasCap.Api.DoorBird.Sinks

Pluggable event sink implementations (Redis, Azure Tables, Azure Blob Storage) for the CasCap.Api.DoorBird door station integration library.

CasCap.Api.Buderus.Sinks

Pluggable event sink implementations (Redis, Azure Tables) for the CasCap.Api.Buderus heating integration library.

CasCap.Api.Fronius.Sinks

Pluggable event sink implementations (Redis, Azure Tables) for the CasCap.Api.Fronius solar inverter integration library.

CasCap.Api.Knx.Sinks

Pluggable event sink implementations (Redis, Azure Tables) for the CasCap.Api.Knx building automation integration library.

CasCap.Api.Voice

Provider-neutral speech-to-text and text-to-speech components for .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.7.0 0 10/21/2026
1.6.4 173 10/4/2026
1.6.3 235 9/25/2026
1.6.2 190 9/23/2026
1.6.1 123 9/21/2026
1.6.0 281 9/19/2026
1.5.5 199 9/11/2026
1.5.4 117 9/1/2026
1.5.3 213 8/18/2026
1.5.2 225 7/15/2026
1.5.1 231 6/26/2026
1.5.0 315 6/12/2026
1.4.13 223 6/10/2026
1.4.12 250 5/27/2026
1.4.11 230 5/26/2026
1.4.10 178 5/21/2026
1.4.9 133 5/20/2026
1.4.8 379 5/13/2026
1.4.7 293 5/8/2026
1.4.6 144 5/4/2026
Loading failed