JJConsulting.Infisical integrates Infisical secrets with .NET configuration and dependency injection.
Install from NuGet:
dotnet add package JJConsulting.InfisicalOr add a package reference manually:
<ItemGroup>
<PackageReference Include="JJConsulting.Infisical" Version="1.0.0" />
</ItemGroup>Or with Package Manager Console:
Install-Package JJConsulting.InfisicalServiceTokenInfisicalConfig: use Infisical service token authentication.MachineIdentityInfisicalConfig: use machine identity (ClientId/ClientSecret) authentication.InfisicalConfig: base configuration type (inherit it to use with custom authentication services).
Use whichever startup surface your app already uses:
IHostBuilder - Configures both the Infisical configuration provider and DI services
AddInfisical(ServiceTokenInfisicalConfig config)AddInfisical(MachineIdentityInfisicalConfig config)AddInfisical<TAuthenticationService>(InfisicalConfig config)
IConfigurationBuilder - Registers only the Infisical configuration provider
AddInfisical(ServiceTokenInfisicalConfig config)AddInfisical(MachineIdentityInfisicalConfig config)AddInfisical<TAuthenticationService>(InfisicalConfig config)
IServiceCollection - Registers only the Infisical DI services
AddInfisical(ServiceTokenInfisicalConfig config)AddInfisical(MachineIdentityInfisicalConfig config)AddInfisical<TAuthenticationService>(InfisicalConfig config)
IInfisicalAuthenticationServiceGetBearerTokenAsync(): returns the bearer token used for Infisical API calls.IInfisicalSecretsServiceGetSecretsAsync(): fetches all secrets for the configured project/path/environment.GetSecretAsync(string key): fetches one secret by key.
appsettings.json:
{
"Infisical": {
"Environment": "prod",
"ProjectId": "your-project-id",
"ServiceToken": "your-service-token",
"SecretPath": "/",
"Url": "https://app.infisical.com"
}
}Program.cs:
using JJConsulting.Infisical.Configuration;
var infisicalConfig = ServiceTokenInfisicalConfig
.FromConfiguration(builder.Configuration.GetSection("Infisical"));
builder.Host.AddInfisical(infisicalConfig);appsettings.json:
{
"Infisical": {
"Environment": "prod",
"ProjectId": "your-project-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"SecretPath": "/",
"Url": "https://app.infisical.com"
}
}Program.cs:
using JJConsulting.Infisical.Configuration;
var infisicalConfig = MachineIdentityInfisicalConfig
.FromConfiguration(builder.Configuration.GetSection("Infisical"));
builder.Host.AddInfisical(infisicalConfig);When creating secrets in Infisical for .NET, use double underscore (__) in the secret key to represent nesting.
Examples of keys in Infisical:
MySettings__MyKeyConnectionStrings__DefaultConnectionLogging__LogLevel__Default
In .NET, these are available as standard configuration paths with :.
Example with IConfiguration:
var value = builder.Configuration["MySettings:MyKey"];
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
var logLevel = builder.Configuration["Logging:LogLevel:Default"];IInfisicalSecretsService is registered by AddInfisical:
using JJConsulting.Infisical.Services;
public class MyService(IInfisicalSecretsService secretsService)
{
public async Task UseSecretsAsync()
{
var all = await secretsService.GetSecretsAsync();
var single = await secretsService.GetSecretAsync("DATABASE_PASSWORD");
}
}Urldefaults tohttps://app.infisical.com.- If
Urlends with/api, it is normalized automatically. SecretPathdefaults to/and cannot be empty.- Service-token auth throws if
ServiceTokenis null/empty/whitespace.
MIT