NativeCredentialStore 2.0.0

dotnet add package NativeCredentialStore --version 2.0.0                
NuGet\Install-Package NativeCredentialStore -Version 2.0.0                
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="NativeCredentialStore" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NativeCredentialStore --version 2.0.0                
#r "nuget: NativeCredentialStore, 2.0.0"                
#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.
// Install NativeCredentialStore as a Cake Addin
#addin nuget:?package=NativeCredentialStore&version=2.0.0

// Install NativeCredentialStore as a Cake Tool
#tool nuget:?package=NativeCredentialStore&version=2.0.0                

Native Credential Store

This project is simply a wrapper of this project docker-credential-helpers. It provides similiar APIs as the docker-credential-helpers does.

All credit is due to the people who makes docker-credential-helpers.

This library aims to provide easy-to-use and cross-platform APIs for interacting with native credential storage such as Windows Credential Manager or OSX keychain. Dotnet does have a capability for storing/retreiving credential (or sensitive data) called Data Protection API. To my knowledge this API is only available on Windows, hence the motivation to make this library cross-platform.

Install

Install from Nuget.

dotnet add package NativeCredentialStore --version 0.0.0

Usage

To access the native credential storage, you must have a IDockerCredentialHelper object and there are 2 ways to get it:

  1. Via the .NET Dependency Injection container - using AddDockerCredentialHelper()
    using Microsoft.Extensions.DependencyInjection;
    using NativeCredentialStore.DockerCredentialHelper;
    
    var serviceProvider = new ServiceCollection()
      .AddDockerCredentialHelper()
      .BuildServiceProvider();
    
    var dockerCredentialHelper = serviceProvider.GetRequiredService<IDockerCredentialHelper>();
    
  2. Via the factory class CredentialStoreFactory.GetDockerCredentialHelper(...)
    using static NativeCredentialStore.CredentialStoreFactory;
    
    var dockerCredentialHelper = GetDockerCredentialHelper();
    

Examples

using NativeCredentialStore.DockerCredentialHelper;
using static NativeCredentialStore.CredentialStoreFactory;

var dockerCredentialHelper = GetDockerCredentialHelper();

var credentials = new Credentials
{
  ServerURL = "http://nativecredentialstore.com",
  Username = "foo@email.com",
  Secret = "password"
};

// No return - can be used to update existing Credentials
await dockerCredentialHelper.StoreAsync(credentials);

// Return the same Credentials object we stored
var storedCredentials = await dockerCredentialHelper.GetAsync("http://nativecredentialstore.com");

// Return a dictionary looking like this:
// {"http://nativecredentialstore.com": "foo@email.com"}
var credentialsDict = await dockerCredentialHelper.ListAsync();

// Erase/remove the credentials - this is idempontent
await dockerCredentialHelper.EraseAsync("http://nativecredentialstore.com");

// Return an empty dictionary if there's no credentials
credentialsDict = await dockerCredentialHelper.ListAsync();

How does it works?

During compilation, this project determines which executable files to download based on the OS platform. Then during runtime, it calls those executable to perform the commands (get, erase, store, and list).

The executables will be first downloaded to the project's $(ToolsFolder) path. Then they are copied to the bin folder so that it is visible for the code to see. When a client calls one of the methods such as INativeCredentialStore.GetAsync(...), it will start a process to call the appropriate executable and pass the arguments to that executable. The output of the executable will be serialized to a C# object and it returns this object to the client.

When generating a nuget package, it will download all executables (for differnt OS's and platform architecture) and pack all those files inside the nuget package (under contentFiles folder). When a consumer project has a reference to the NativeCredentialStore library, all the executables will be copied to the bin folder of the consumer project.

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
2.0.0 133 10/18/2024
1.0.1 119 10/6/2024
0.0.1 146 3/21/2024
0.0.0 198 3/19/2024