Helsedir.Hint.Grunnmur.Klienter.EntraId 1.2.2

dotnet add package Helsedir.Hint.Grunnmur.Klienter.EntraId --version 1.2.2
                    
NuGet\Install-Package Helsedir.Hint.Grunnmur.Klienter.EntraId -Version 1.2.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="Helsedir.Hint.Grunnmur.Klienter.EntraId" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Helsedir.Hint.Grunnmur.Klienter.EntraId" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Helsedir.Hint.Grunnmur.Klienter.EntraId" />
                    
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 Helsedir.Hint.Grunnmur.Klienter.EntraId --version 1.2.2
                    
#r "nuget: Helsedir.Hint.Grunnmur.Klienter.EntraId, 1.2.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 Helsedir.Hint.Grunnmur.Klienter.EntraId@1.2.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=Helsedir.Hint.Grunnmur.Klienter.EntraId&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Helsedir.Hint.Grunnmur.Klienter.EntraId&version=1.2.2
                    
Install as a Cake Tool

EntraId HttpClient

Purpose

This package is intended for internal use at the Norwegian Directorate of Health (Helsedirektoratet) to provide a consistent way to retrieve tokens from Entra ID and maintain a uniform configuration setup.

Usage

Register the EntraId client with shared configuration and add per-client audience override:

using Hdir.Hint.Grunnmur.Klienter.EntraId;

// Register with shared configuration (TenantId, KlientId, KlientSecret)
services.AddEntraIdKlient(o =>
{
    o.KlientId = config["EntraIdKlient:KlientId"];
    o.TenantId = config["EntraIdKlient:TenantId"];
    o.KlientSecret = config["EntraIdKlient:KlientSecret"];
    o.Audience = config["EntraIdKlient:Audience"];
});

// HttpClient with specific audience
services.AddHttpClient<MyHttpClient>()
    .AddEntraIdHandler(o => o.Audience = config["EntraIdKlient:Audiences:MyService"]);

// HttpClient using default audience from base section
services.AddHttpClient<AnotherHttpClient>()
    .AddEntraIdHandler();

Expected configuration:

"EntraIdKlient": {
    "KlientId": "<your client id>",
    "TenantId": "<tenantId>",
    "KlientSecret": "<your secret>",
    "Audiences": {
        "MyService": "<audience for MyService>",
        "AnotherService": "<audience for AnotherService>"
    }
}

Legacy Approach (Backwards Compatible)

Add with:

using Hdir.Hint.Grunnmur.Klienter.EntraId
// ...
services.AddEntraIdKlient();

Expected configuration:

"EntraIdKlient": {
    // Audience must always be specified and is sufficient if running in Azure with ManagedIdentityCredential() available
    "Audience": "<API audience>", // For HINT this is api://hint-test for test and api://hint for production

    // If only KlientId is specified without a secret, ManagedIdentityCredential(klientId) will be attempted
    "KlientId": "<your client id>",

    // TenantId only needs to be specified if clientId/clientSecret are also provided, then ClientSecretCredential(tenantId, clientId, secret) is used
    "TenantId": "<tenantId>", // The Norwegian Directorate of Health's tenantId is "6ba1bd5c-750f-4ad6-aba3-0f95585bc21f"
            
    // KlientSecret must be provided if ClientSecretCredential(tenantId, clientId, secret) should be used
    "KlientSecret": "<your secret>"
}

Handler usage:

services.AddEntraIdKlient();
services.AddHttpClient<MyHttpClientThatNeedsEntraId>()
    .AddHttpMessageHandler<EntraIdHandler>();

Alternatively, to change which configuration section to use:

.AddHttpMessageHandler(sp => new EntraIdHandler(
    sp.GetRequiredService<IEntraIdKlient>(),
    "YourHttpClientConfigSection"));

If no configuration is provided, the Handler cannot be used. In that case, _entraIdKlient.HentEntraIdToken(...) must be used directly with input arguments.

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 was computed.  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

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.2.2 166 2/20/2026
1.2.1 93 2/17/2026
1.2.0 95 2/17/2026
1.0.13 577 12/11/2025
1.0.12 355 9/24/2025

- 1.2.2 - Re-added .NET8 target framework
- 1.2.1 - Updated README
- 1.2.0 - Added IOptions pattern support with EntraIdKlientOptions and fluent AddEntraIdHandler() API
- 1.1.0 - Removed dependency of LazyCache
- 1.0.13 - Updated to use a shared pipeline for building the package
- Første release