Fhi.ClientCredentialsKeypairs 1.0.0-beta.4

This is a prerelease version of Fhi.ClientCredentialsKeypairs.
There is a newer version of this package available.
See the version list below for details.
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.ClientCredentialsKeypairs --version 1.0.0-beta.4
                    
NuGet\Install-Package Fhi.ClientCredentialsKeypairs -Version 1.0.0-beta.4
                    
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.ClientCredentialsKeypairs" Version="1.0.0-beta.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fhi.ClientCredentialsKeypairs" Version="1.0.0-beta.4" />
                    
Directory.Packages.props
<PackageReference Include="Fhi.ClientCredentialsKeypairs" />
                    
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.ClientCredentialsKeypairs --version 1.0.0-beta.4
                    
#r "nuget: Fhi.ClientCredentialsKeypairs, 1.0.0-beta.4"
                    
#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.
#addin nuget:?package=Fhi.ClientCredentialsKeypairs&version=1.0.0-beta.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Fhi.ClientCredentialsKeypairs&version=1.0.0-beta.4&prerelease
                    
Install as a Cake Tool

Client Credentials Usage

Configuration file section

  1. Add the following configuration section to your appsettings.json files, and populate it appropriately.
  "ClientCredentialsConfiguration": {
    "clientName": "",
    "authority": "",
    "clientId": "",
    "grantTypes": [ "client_credentials" ],
    "scopes": [ ],
    "secretType": "private_key_jwt:RsaPrivateKeyJwtSecret",
    "rsaPrivateKey": "",
    "rsaKeySizeBits": 4096,
    "privateJwk": "",
    "Apis": [
      {
        "Name": "", // Tip:  Use nameof(YourService)
        "Url": ""
      }
    ],
    "refreshTokenAfterMinutes":  8  // Set approx 20% less than lifetime of access token
  }

Client Credentials using Keypairs

  1. Add package 'Fhi.ClientCredentialsKeypairs' to your project

  2. In your Program.cs file, or if older Startup.cs, add the following code section (for the outgoing interfaces):

    var clientCredentialsConfiguration = services.AddClientCredentialsKeypairs(Configuration);
    services.AddHttpClient(nameof(YourService), c =>
    {
       c.Timeout = new TimeSpan(0, 0, 0, 10);
       c.BaseAddress = clientCredentialsConfiguration.UriToApiByName(nameof(YourService));
    })
    .AddHttpMessageHandler<HttpAuthHandler>()
    .AddTypedClient(c => RestService.For<IExternalApi>(c, new RefitSettings
    {
       ContentSerializer = new SystemTextJsonContentSerializer(services.DefaultJsonSerializationOptions())
    }));

replacing YourService with the service you have done for accessing the external api, and replace IExternalApi with the Refit interface for whatever external api you want to access.

The Configuration property is the injected IConfiguration property from the Startup.cs file.

If you don't use Refit, you can just skip the last part, and get the named client from the injected HttpFactory in your service. It will still have the authenticationhandler, so you don't need to do anything more there to get the bearer token. It will be added automatically.

Client Credentials using Client Secrets

If you want to disable the authorization for some reason, you can add another property named Enable to the ClientCredentialsConfiguration, it is default true.

  1. Add package Fhi.ClientCredentialsUsingSecrets to your project
  2. In your Program.cs file, create an instance of the ClientCredentialsSetup class using an IConfiguration parameter.
  3. Using the created instance call the method ConfigureServices.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on Fhi.ClientCredentialsKeypairs:

Package Downloads
Fhi.ClientCredentials.TestSupport

This package contains tests that checks your appsettings.*.json files for correct configuration of the ClientCredentials package.

Fhi.ClientCredentials.Refit

Builder to simplify setup of ClientCredentials when using the Refit library.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.3.0 258 6/4/2025
3.2.0 1,718 3/31/2025
3.1.0 1,273 2/17/2025
3.0.0 2,679 11/26/2024
2.0.3 4,159 10/7/2024
2.0.2 362 10/2/2024
2.0.0 153 10/1/2024
1.4.1 370 9/23/2024
1.4.0 143 9/20/2024
1.2.0 11,336 8/19/2023
1.1.0 1,584 8/9/2023
1.0.0 5,285 2/16/2023