Mihir.AspNetCore.Authentication.Basic 2.0.0

Basic Scheme Authentication Implementation for ASP.NET Core 2.2

Suggested Alternatives

AspNetCore.Authentication.Basic

Additional Details

This NuGet package has been made obsolete and moved to a new package named 'AspNetCore.Authentication.Basic'. Please consider removing this package and download the new one as there will be no future updates on this package. Sorry for the inconvenience caused. This was done purely for the naming of the package. New package name is 'AspNetCore.Authentication.Basic' which can be downloaded using NuGet Package Manager or from AspNetCore.Authentication.Basic.

There is a newer version of this package available.
See the version list below for details.
Install-Package Mihir.AspNetCore.Authentication.Basic -Version 2.0.0
dotnet add package Mihir.AspNetCore.Authentication.Basic --version 2.0.0
<PackageReference Include="Mihir.AspNetCore.Authentication.Basic" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mihir.AspNetCore.Authentication.Basic --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Mihir.AspNetCore.Authentication.Basic

Basic Scheme Authentication Implementation for ASP.NET Core 2.2

Installing

This library is published on NuGet. So the NuGet package can be installed directly to your project if you wish to use it without making any custom changes to the code.

Download directly from Mihir.AspNetCore.Authentication.Basic.

Or by running the below command on your project.

PM> Install-Package Mihir.AspNetCore.Authentication.Basic

Example Usage

Setting it up is quite simple. You will need basic working knowledge of ASP.NET Core 2.2 to get started using this code.

On Startup.cs, as shown below, add 2 lines in ConfigureServices method services.AddAuthentication(BasicDefaults.AuthenticationScheme).AddBasic&lt;BasicUserValidationService&gt;(options =&gt; { options.Realm = &quot;My App&quot;; });. And a line app.UseAuthentication(); in Configure method.

Also add an implementation of IBasicUserValidationService as shown below in BasicUserValidationService.cs.

NOTE: Always use HTTPS (SSL Certificate) protocol in production when using Basic authentication.

Startup.cs
using Mihir.AspNetCore.Authentication.Basic;
public class Startup
{
	public Startup(IConfiguration configuration)
	{
		Configuration = configuration;
	}

	public IConfiguration Configuration { get; }

	public void ConfigureServices(IServiceCollection services)
	{
		// Add the Basic scheme authentication here..
		// AddBasic extension takes an implementation of IBasicUserValidationService for validating the username and password. 
		// It also requires Realm to be set in the options.
		services.AddAuthentication(BasicDefaults.AuthenticationScheme)
			.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });

		services.AddMvc();
	}

	public void Configure(IApplicationBuilder app, IHostingEnvironment env)
	{
		app.UseAuthentication();
		app.UseMvc();
	}
}
BasicUserValidationService.cs
using Mihir.AspNetCore.Authentication.Basic;
public class BasicUserValidationService : IBasicUserValidationService
{
	private readonly ILogger<BasicUserValidationService> _logger;
	
	public BasicUserValidationService(ILogger<BasicUserValidationService> logger)
	{
		_logger = logger;
	}

	public Task<bool> IsValidAsync(string username, string password)
	{
		try
		{
			// write your implementation here and return true or false depending on the validation..
			return Task.FromResult(true);
		}
		catch (Exception e)
		{
			_logger.LogError(e, e.Message);
			throw;
		}
	}
}

References

License

MIT License

Mihir.AspNetCore.Authentication.Basic

Basic Scheme Authentication Implementation for ASP.NET Core 2.2

Installing

This library is published on NuGet. So the NuGet package can be installed directly to your project if you wish to use it without making any custom changes to the code.

Download directly from Mihir.AspNetCore.Authentication.Basic.

Or by running the below command on your project.

PM> Install-Package Mihir.AspNetCore.Authentication.Basic

Example Usage

Setting it up is quite simple. You will need basic working knowledge of ASP.NET Core 2.2 to get started using this code.

On Startup.cs, as shown below, add 2 lines in ConfigureServices method services.AddAuthentication(BasicDefaults.AuthenticationScheme).AddBasic&lt;BasicUserValidationService&gt;(options =&gt; { options.Realm = &quot;My App&quot;; });. And a line app.UseAuthentication(); in Configure method.

Also add an implementation of IBasicUserValidationService as shown below in BasicUserValidationService.cs.

NOTE: Always use HTTPS (SSL Certificate) protocol in production when using Basic authentication.

Startup.cs
using Mihir.AspNetCore.Authentication.Basic;
public class Startup
{
	public Startup(IConfiguration configuration)
	{
		Configuration = configuration;
	}

	public IConfiguration Configuration { get; }

	public void ConfigureServices(IServiceCollection services)
	{
		// Add the Basic scheme authentication here..
		// AddBasic extension takes an implementation of IBasicUserValidationService for validating the username and password. 
		// It also requires Realm to be set in the options.
		services.AddAuthentication(BasicDefaults.AuthenticationScheme)
			.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });

		services.AddMvc();
	}

	public void Configure(IApplicationBuilder app, IHostingEnvironment env)
	{
		app.UseAuthentication();
		app.UseMvc();
	}
}
BasicUserValidationService.cs
using Mihir.AspNetCore.Authentication.Basic;
public class BasicUserValidationService : IBasicUserValidationService
{
	private readonly ILogger<BasicUserValidationService> _logger;
	
	public BasicUserValidationService(ILogger<BasicUserValidationService> logger)
	{
		_logger = logger;
	}

	public Task<bool> IsValidAsync(string username, string password)
	{
		try
		{
			// write your implementation here and return true or false depending on the validation..
			return Task.FromResult(true);
		}
		catch (Exception e)
		{
			_logger.LogError(e, e.Message);
			throw;
		}
	}
}

References

License

MIT License

Release Notes

- Microsoft.AspNetCore.Authentication NuGet package upgraded to 2.2.0
- Microsoft.AspNetCore.All package upgraded to 2.0.9 on SampleWebApi project to fix the vulnerabilities found in the previous versions
- New SampleWebApi.Shared and SampleWebApi_2_2 project added for WebApi for .NET Core 2.2 on the github repository
- Fixed a bug in the Sample project to do with Object Null Exception

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.1 181 12/18/2019
2.0.0 128 10/25/2019
1.0.2 644 3/23/2018
1.0.1 505 3/23/2018
1.0.0 404 3/22/2018