All Projects → msmolka → Znetcs.aspnetcore.authentication.basic

msmolka / Znetcs.aspnetcore.authentication.basic

Licence: mit
A simple basic authentication middleware.

Programming Languages

basic
69 projects

Projects that are alternatives of or similar to Znetcs.aspnetcore.authentication.basic

SeoTags
SeoTags create all SEO tags you need such as meta, link, twitter card (twitter:), open graph (og:), and JSON-LD schema (structred data).
Stars: ✭ 113 (+182.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core, asp-net-core-mvc
DNZ.MvcComponents
A set of useful UI-Components (HtmlHelper) for ASP.NET Core MVC based-on Popular JavaScript Plugins (Experimental project).
Stars: ✭ 25 (-37.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core, asp-net-core-mvc
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+117.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core, asp-net-core-mvc
AspNetCore.Unobtrusive.Ajax
Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
Stars: ✭ 46 (+15%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core, asp-net-core-mvc
OnlineUsers-Counter-AspNetCore
Display online users count in ASP.NET Core in two ways (Cookie - SingalR)
Stars: ✭ 29 (-27.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core, asp-net-core-mvc
Equinoxproject
Full ASP.NET Core 5 application with DDD, CQRS and Event Sourcing concepts
Stars: ✭ 5,120 (+12700%)
Mutual labels:  asp-net-core, aspnetcore, aspnet-core, asp-net-core-mvc
high-performance-aspnet-core-workshop
Sample application used in the High-Performance ASP.NET Core Workshop
Stars: ✭ 29 (-27.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core
AspNetCore-Dynamic-Permission
Dynamic Permission Samples in ASP.NET Core and ASP.NET MVC 5.
Stars: ✭ 19 (-52.5%)
Mutual labels:  aspnet-core, asp-net-core, asp-net-core-mvc
Aspnet5identityserverangularimplicitflow
OpenID Connect Code / Implicit Flow with Angular and ASP.NET Core 5 IdentityServer4
Stars: ✭ 670 (+1575%)
Mutual labels:  aspnetcore, aspnet-core, authentication
Ext.NET
Ext.NET public Issues.
Stars: ✭ 28 (-30%)
Mutual labels:  aspnetcore, asp-net-core, asp-net-core-mvc
Znetcs.aspnetcore.logging.entityframeworkcore
This is Entity Framework Core logger and logger provider. A small package to allow store logs in any data store using Entity Framework Core.
Stars: ✭ 24 (-40%)
Mutual labels:  asp-net-core, aspnetcore, aspnet-core
AspNetCore.Mvc.FluentActions
Fluent Actions for ASP.NET Core MVC are abstractions of regular MVC actions that are converted into MVC actions during startup.
Stars: ✭ 17 (-57.5%)
Mutual labels:  aspnetcore, asp-net-core, asp-net-core-mvc
Aspnetcore Developer Roadmap
Roadmap to becoming an ASP.NET Core developer in 2021
Stars: ✭ 8,248 (+20520%)
Mutual labels:  asp-net-core, aspnetcore, aspnet-core
TheLastTime
C# .NET 5 Blazor WebAssembly Progressive Web Application that tracks when was the last time you did something
Stars: ✭ 23 (-42.5%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core
MvcControlsToolkit.Core
Core Code for MvcControlsToolkit packages
Stars: ✭ 13 (-67.5%)
Mutual labels:  aspnetcore, asp-net-core, asp-net-core-mvc
awesome-dotnet-async
A curated list of awesome articles and resources to learning and practicing about async, threading, and channels in .Net platform. 😉
Stars: ✭ 84 (+110%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-35%)
Mutual labels:  aspnetcore, aspnet-core, asp-net-core
Awesome Microservices Netcore
💎 A collection of awesome training series, articles, videos, books, courses, sample projects, and tools for Microservices in .NET Core
Stars: ✭ 865 (+2062.5%)
Mutual labels:  asp-net-core, aspnetcore, aspnet-core
PersianDataAnnotations
PersianDataAnnotations is ASP.NET Core MVC & ASP.NET MVC Custom Localization DataAnnotations (Localized MVC Errors) for Persian(Farsi) language - فارسی سازی خطاهای اعتبارسنجی توکار ام.وی.سی. و کور.ام.وی.سی. برای نمایش اعتبار سنجی سمت کلاینت
Stars: ✭ 38 (-5%)
Mutual labels:  aspnetcore, asp-net-core, asp-net-core-mvc
Home
Asp.net core Mvc Controls Toolkit
Stars: ✭ 33 (-17.5%)
Mutual labels:  aspnetcore, asp-net-core, asp-net-core-mvc

ZNetCS.AspNetCore.Authentication.Basic

NuGet

A simple basic authentication middleware.

Installing

Install using the ZNetCS.AspNetCore.Authentication.Basic NuGet package

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

Changes in 5.0.0

Added direct references to latest framework and removed no longer supported frameworks. Added possibility to suppress WWWAuthenticate header globally not only on Ajax request.

Important change in 4.0.0

From now assembly is signed.

Important change in 3.0.0

The OnValidatePrincipal will not return AuthenticationResult any more. To simplify process can simply return Task.CompletedTask. Also to make success authentication Principal have to be assigned to ValidatePrincipalContext context.

Usage

When you install the package, it should be added to your .csproj. Alternatively, you can add it directly by adding:

<ItemGroup>
    <PackageReference Include="ZNetCS.AspNetCore.Authentication.Basic" Version="5.0.0" />
</ItemGroup>

In order to use the basic authentication middleware, you must configure the services in the Configure and ConfigureServices call of Startup. Because basic authentication is manual process handled on each request, there is need to validate credentials manually (see below).

using ZNetCS.AspNetCore.Authentication.Basic;
using ZNetCS.AspNetCore.Authentication.Basic.Events;
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{   

    // default authentication initialization
    app.UseAuthentication();

    // other middleware e.g. MVC etc
}

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
        .AddBasicAuthentication(
            options =>
            {
                options.Realm = "My Application";
                options.Events = new BasicAuthenticationEvents
                {
                    OnValidatePrincipal = context =>
                    {
                        if ((context.UserName == "userName") && (context.Password == "password"))
                        {
                            var claims = new List<Claim>
                            {
                                new Claim(ClaimTypes.Name, context.UserName, context.Options.ClaimsIssuer)
                            };

                            var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
                            context.Principal = principal;
                        }
                        else 
                        {
                            // optional with following default.
                            // context.AuthenticationFailMessage = "Authentication failed."; 
                        }

                        return Task.CompletedTask;
                    }
                };
            });
}

or using dependency injection:

public class AuthenticationEvents : BasicAuthenticationEvents
{
    #region Public Methods

    /// <inheritdoc/>
    public override Task ValidatePrincipalAsync(ValidatePrincipalContext context)
    {
        if ((context.UserName == "userName") && (context.Password == "password"))
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.Name, context.UserName, context.Options.ClaimsIssuer)
            };

            var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
            context.Principal = principal;
        }

        return Task.CompletedTask;
    }

    #endregion
}

and then registration

public void ConfigureServices(IServiceCollection services)
{
    services.AddScoped<AuthenticationEvents>();

    services
        .AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
        .AddBasicAuthentication(
            options =>
            {
                options.Realm = "My Application";
                options.EventsType = typeof(AuthenticationEvents)
            });
}

As from version 3.0.1 You can suppress the response WWW-Authenticate header (avoiding the browser to show a popup) for ajax requests by using a switch.

public void ConfigureServices(IServiceCollection services)
{
    services.AddScoped<AuthenticationEvents>();

    services
        .AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
        .AddBasicAuthentication(
            options =>
            {
                options.Realm = "My Application";
                options.AjaxRequestOptions.SuppressWwwAuthenticateHeader = true;
            });
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].