Bazinga.AspNetCore.Authentication.Basic 2.0.1

Basic Authentication Scheme for ASP.NET Core 2.0

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.

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

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

Release Notes

Bugfix: Unhandled exception logs the inner exception

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.1 27,188 11/30/2017
2.0.0 976 9/10/2017