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
<PackageReference Include="Helsedir.Hint.Grunnmur.Klienter.EntraId" Version="1.2.2" />
<PackageVersion Include="Helsedir.Hint.Grunnmur.Klienter.EntraId" Version="1.2.2" />
<PackageReference Include="Helsedir.Hint.Grunnmur.Klienter.EntraId" />
paket add Helsedir.Hint.Grunnmur.Klienter.EntraId --version 1.2.2
#r "nuget: Helsedir.Hint.Grunnmur.Klienter.EntraId, 1.2.2"
#:package Helsedir.Hint.Grunnmur.Klienter.EntraId@1.2.2
#addin nuget:?package=Helsedir.Hint.Grunnmur.Klienter.EntraId&version=1.2.2
#tool nuget:?package=Helsedir.Hint.Grunnmur.Klienter.EntraId&version=1.2.2
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
New Recommended Approach (IOptions Pattern)
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 | Versions 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. |
-
net10.0
- Azure.Identity (>= 1.17.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.3)
- Microsoft.Extensions.Configuration (>= 10.0.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
- Microsoft.Extensions.Logging (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.3)
-
net8.0
- Azure.Identity (>= 1.17.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.3)
- Microsoft.Extensions.Configuration (>= 10.0.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Http (>= 10.0.3)
- Microsoft.Extensions.Logging (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- 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