.NET Core integration

Piotr Gankiewicz edited this page Dec 4, 2016 · 6 revisions

API

Install-Package Lockbox.Api

Modify Program.cs:

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseStartup<LockboxStartup>()
    .Build();

host.Run();

Start the application using dotnet run command and open the web browser at http://localhost:5000.

Adjust the available appsettings.json configuration:

{
    "feature": {
        "entrySizeBytesLimit": 524288,
        "entriesPerBoxLimit": 20,
        "usersPerBoxLimit": 20,
        "boxesPerUserLimit": 3,
        "requireAdminToCreateUser": false
    },
    "lockbox": {
        "secretKey": "your_secret_key"
    },
    "mongoDb": {
        "connectionString": "mongodb://localhost:27017",
        "database": "Lockbox"
    }
}

Or make use of the following environment variables:

LOCKBOX_SECRET_KEY
LOCKBOX_MONGO_CONNECTION_STRING
LOCKBOX_MONGO_DATABASE

Client

Install-Package Lockbox.Client

Add the following line of code to the ConfigurationBuilder instance within Startup.cs constructor:

.AddLockbox()

So it should look like this:

public IConfiguration Configuration { get; set; }

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .AddLockbox(encryptionKey: "encryption_key",  
            apiUrl: "api_url",                         
            apiKey: "user_api_key",                    
            boxName: "box_name",
            entryKey: "entry_name_for_app_settings");

    Configuration = builder.Build();
}

Run the application and you will see updated configuration based on the encrypted entry value stored in Lockbox. Use the provided optional parameters or make use of the following environment variables:

LOCKBOX_ENCRYPTION_KEY
LOCKBOX_API_URL
LOCKBOX_API_KEY
LOCKBOX_BOX_NAME
LOCKBOX_ENTRY_KEY