Bazinga.AspNetCore.Authentication.Basic 2.0.1

Install-Package Bazinga.AspNetCore.Authentication.Basic -Version 2.0.1
dotnet add package Bazinga.AspNetCore.Authentication.Basic --version 2.0.1
<PackageReference Include="Bazinga.AspNetCore.Authentication.Basic" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bazinga.AspNetCore.Authentication.Basic --version 2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bazinga.AspNetCore.Authentication.Basic, 2.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bazinga.AspNetCore.Authentication.Basic as a Cake Addin
#addin nuget:?package=Bazinga.AspNetCore.Authentication.Basic&version=2.0.1

// Install Bazinga.AspNetCore.Authentication.Basic as a Cake Tool
#tool nuget:?package=Bazinga.AspNetCore.Authentication.Basic&version=2.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Bazinga.AspNetCore.Authentication.Basic

Build status NuGet codecov Basic Authentication for Microsoft ASP.NET Core Security

Microsoft doesn't ship a Basic Authentication package with ASP.NET Core Security for a good reason. While that doesn't stop us needing such implementation for testing, this is not advised for production systems due to the many pitfalls and insecurities.

Sample usages, with hard-coded credentials:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddAuthentication()
        .AddBasicAuthentication(credentials => 
            Task.FromResult(
                credentials.username == "myUsername" 
                && credentials.password == "myPassword"));
}

Or by defining a service to register. Allowing your validator to take dependencies through Dependency Injection:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthorization()
        .AddBasicAuthentication<DatabaseBasicCredentialVerifier>();
}

// With your own validator
public class DatabaseBasicCredentialVerifier : IBasicCredentialVerifier
{
    private readonly IUserRepository _db;
    
    public DatabaseBasicCredentialVerifier(IUserRepository db) => _db = db;

    public Task<bool> Authenticate(string username, string password)
    {
        return _db.IsValidAsync(username, password);
    }
}

And finally, since ASP.NET Core 2.0, the single middeware for authentication:

public void Configure(IApplicationBuilder app)
{
    app.UseAuthentication();
    app.AddMvc();
}

For better understanding of the ASP.NET Core Identity, see Microsoft docs

License

Licensed under MIT

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.1 246,629 11/30/2017
2.0.0 1,401 9/10/2017

Bugfix: Unhandled exception logs the inner exception