Fhi.Lmr.Authentication.ClientCredentials 10.2.2

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Fhi.Lmr.Authentication.ClientCredentials --version 10.2.2
                    
NuGet\Install-Package Fhi.Lmr.Authentication.ClientCredentials -Version 10.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="Fhi.Lmr.Authentication.ClientCredentials" Version="10.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fhi.Lmr.Authentication.ClientCredentials" Version="10.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Fhi.Lmr.Authentication.ClientCredentials" />
                    
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 Fhi.Lmr.Authentication.ClientCredentials --version 10.2.2
                    
#r "nuget: Fhi.Lmr.Authentication.ClientCredentials, 10.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 Fhi.Lmr.Authentication.ClientCredentials@10.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=Fhi.Lmr.Authentication.ClientCredentials&version=10.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Fhi.Lmr.Authentication.ClientCredentials&version=10.2.2
                    
Install as a Cake Tool

Fhi.Lmr.Authentication.ClientCredentials

NuGet-pakke for automatisk token-håndtering ved maskin-til-maskin-kommunikasjon mot API-er beskyttet av HelseId, Entra ID eller Maskinporten.

Installasjon

dotnet add package Fhi.Lmr.Authentication.ClientCredentials

Konfigurasjon

appsettings.json

{
  "OidcClients": {
    "HelseIdClient": {
      "Authority": "https://helseid-sts.test.nhn.no",
      "ClientId": "din-client-id",
      "PrivateKey": "{\"d\":\"...\",\"kty\":\"RSA\",\"n\":\"...\"}"
    },
    "EntraIdClient": {
      "Authority": "https://login.microsoftonline.com/{tenant-id}/v2.0",
      "ClientId": "din-client-id",
      "PrivateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
      "kid": "SERTIFIKAT_THUMBPRINT"
    },
    "MaskinportenClient": {
      "Authority": "https://test.maskinporten.no",
      "ClientId": "din-client-id",
      "PrivateKey": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
      "kid": "din-key-id"
    }
  },
  "Apis": {
    "EksempelApi": {
      "BaseAddress": "https://api.example.com/",
      "HttpClientName": "EksempelApiClient",
      "OidcClientName": "HelseIdClient",
      "Scope": "fhi:example/read",
      "UseDPoP": true
    },
    "AnnetApi": {
      "BaseAddress": "https://annet-api.example.com/",
      "HttpClientName": "AnnetApiClient",
      "OidcClientName": "MaskinportenClient",
      "Scope": "fhi:annet/api",
      "resource": "fhi:annet.api"
    }
  }
}

Konfigurasjonsverdier

OidcClients
Felt Beskrivelse Påkrevd
Authority URL til identity provider (brukes for discovery document) Ja
ClientId Klient-ID registrert hos identity provider Ja
PrivateKey Privat nøkkel (JWK-format for HelseId, PEM-format for EntraId/Maskinporten) Ja
kid Key ID - påkrevd for EntraId (hex thumbprint) og Maskinporten Avhengig av IDP
Apis
Felt Beskrivelse Påkrevd
BaseAddress Base-URL til API-et Ja
HttpClientName Navn på HttpClient (brukes med IHttpClientFactory) Ja
OidcClientName Referanse til OidcClient (HelseIdClient, EntraIdClient, eller MaskinportenClient) Ja
Scope Scope som skal forespørres ved token-henting Ja
UseDPoP Aktiver DPoP (kun HelseId) Nei
resource Resource-parameter (kun Maskinporten) Nei

Bruk

Program.cs

using Fhi.Lmr.Authentication.ClientCredentials.ClientCredentials;

var builder = WebApplication.CreateBuilder(args);

// Registrer HTTP-klienter med automatisk token-håndtering
builder.Services.ConfigureHttpClients(builder.Configuration);

var app = builder.Build();
app.Run();

Bruk av HttpClient

public class MinService
{
    private readonly IHttpClientFactory _httpClientFactory;

    public MinService(IHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory;
    }

    public async Task<string> HentDataAsync()
    {
        // HttpClientName fra appsettings
        var client = _httpClientFactory.CreateClient("EksempelApiClient");

        // Token hentes og vedlikeholdes automatisk
        var response = await client.GetAsync("api/data");
        response.EnsureSuccessStatusCode();

        return await response.Content.ReadAsStringAsync();
    }
}

Støttede Identity Providers

Provider Client Assertion DPoP Nøkkelformat
HelseId Ja Ja JWK (JSON)
Entra ID Ja Nei PEM
Maskinporten Ja Nei PEM

Tekniske detaljer

  • Tokens caches automatisk og fornyes ved behov
  • Discovery documents caches for ytelse
  • DPoP-proof genereres automatisk for HelseId når UseDPoP: true
  • Client assertions bygges med riktig format per identity provider
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