ConfigurationFrom1Password 1.0.1

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

ConfigurationFrom1Password

A .NET configuration extension that securely loads secrets from 1Password into your application configuration without hardcoding credentials in your code. This is intended for local development and testing scenarios, not production use. Please use a secure secrets management solution for production applications.

Motivation

I didn't like putting account credentials, passwords, and secret keys directly into code or configuration files. This implementation uses 1Password's CLI to read secrets during application startup, keeping your credentials safe and secure.

Instead of hardcoding sensitive values or storing them in plain text configuration files, this library allows you to reference 1Password secret references (e.g., op://Private/MyVault/password) in your configuration, and they are automatically resolved at runtime.

Features

  • Secure credential management: No credentials stored in code or configuration files
  • 1Password integration: Leverages the 1Password CLI (op.exe) to fetch secrets
  • Seamless configuration replacement: Works with existing .NET configuration system
  • Multiple configuration sources: Supports JSON files, in-memory collections, and more
  • Complex object support: Can resolve secrets in nested configuration objects
  • Connection strings: Works with connection strings and any configuration value

Prerequisites

  • Active 1Password account with stored secrets
  • 1Password CLI installed and configured
  • .NET 8.0 or later

Installation

Add the ConfigurationFrom1Password project to your solution and reference it in your application.

Usage

Basic Setup

Add the .Replace1PasswordSecrets() extension method to your configuration builder after adding your configuration sources. This will scan for any 1Password secret references and replace them with the actual secret values at runtime. Replace sensitive configuration values with 1Password secret references in your appsettings.json:

{
  "NonSensitiveData": "regular-value",
  "SensitiveData": "op://Private/1Password Config Extension Test/password",
  "ConnectionStrings": {
    "DefaultConnection": "op://Private/1Password Config Extension Test/connectionstring"
  }
}

Be Aware: I have not gotten it to work with a ServiceCollection configuration provider, you must use a generic Host or WebApplication builder to use the extension method. If you have a solution for this, please submit a PR.

Console Application

using ConfigurationFrom1Password;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);

builder.Configuration
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

if (builder.Environment.IsDevelopment())
    builder.Configuration.Replace1PasswordSecrets();

// Access your secrets securely
var sensitiveData = builder.Configuration["SensitiveData"];
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");

ASP.NET Core Web Application

using ConfigurationFrom1Password;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json");

if (builder.Environment.IsDevelopment())
    builder.Configuration.Replace1PasswordSecrets();

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

In-Memory Configuration with Secrets

builder.Configuration
    .AddInMemoryCollection([
        new("SensitiveData", "op://Private/MyVault/password")
    ])
    .Replace1PasswordSecrets();

How It Works

  1. The extension scans all configuration values for 1Password secret references (values starting with op://)
  2. For each unique secret reference, it executes the 1Password CLI to retrieve the actual value
  3. The configuration values are replaced with the resolved secrets
  4. Your application accesses the configuration normally, with all secrets securely loaded

The OnePasswordConfigurationProvider uses the op.exe read command to fetch secrets, ensuring that credentials are only retrieved at runtime and never stored in your codebase.

1Password Secret Reference Format

1Password secret references follow this format:

op://<vault>/<item>/<field>

Examples:

  • op://Private/DatabaseCredentials/password
  • op://Private/APIKeys/token
  • op://Private/MyApp/connectionstring

Security Benefits

  • No hardcoded secrets: Credentials never appear in source code
  • Version control safe: Configuration files can be committed without exposing secrets
  • Centralized secret management: All secrets managed through 1Password
  • Audit trail: 1Password provides access logs for secret retrieval
  • Team collaboration: Share secrets securely through 1Password vaults

Testing

The project includes comprehensive tests demonstrating various usage scenarios. Note that tests requiring 1Password access are marked as [Explicit] to prevent accidental execution.

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 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

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.0.2-prerelease.1 41 4/11/2026
1.0.1 48 4/10/2026
1.0.1-prerelease.5 46 4/10/2026