Mihir.AspNetCore.Authentication.Basic 1.0.1

Basic Scheme Authentication Implementation for ASP.NET Core 2.0

There is a newer version of this package available.
See the version list below for details.
Install-Package Mihir.AspNetCore.Authentication.Basic -Version 1.0.1
dotnet add package Mihir.AspNetCore.Authentication.Basic --version 1.0.1
<PackageReference Include="Mihir.AspNetCore.Authentication.Basic" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mihir.AspNetCore.Authentication.Basic --version 1.0.1
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.0

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.0 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.

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.0

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.0 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.

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

- Challenge property moved from BasicOptions to BasicHandler

Version History

Version Downloads Last updated
1.0.2 407 3/23/2018
1.0.1 325 3/23/2018
1.0.0 227 3/22/2018