Custom Auth ASP MVC 5 with Owin Security

Since ASP MVC 5 came out, came with a new security features based on OWIN authentication middleware. So when you created a new project with ASP MVC from Visual Studio, you can choose what kind of authentication you want,

that it’s fine, but the problem is when we want to create a new project using the new Authentication of OWIN. Usually we need to create a Empty or Basic project and choosing No Authentication, and from there, go installing from scratch each of the libraries for authentication and creating and set our classes, because if we choose Individual User Account, Visual Studio will generate the project template with all code source example that we don’t need, you know, roles, manage users, entity framework, the all scheme based authentication that microsoft give us and it’s fine to learning and not more.

So it will be nice if we would have one type of authentication more with the basic assemblies and maybe the set classes but unfortunately we don’t. So tired to create always a empty project and install the assemblies and set the classes every time that I needed to create a new project. I decided to create a base and simple template with just the assemblies of owin and the classes already configured to start to work. No database, Not Entity Framework, not all scheme based security of visual studio. Just only a AccountController with a action post like this:

public ActionResult Login(LoginViewModel model)
{
    if (!ModelState.IsValid)
        return View();

    if (this._accountServices.getUsers().Any(a => a.userName == model.UserName && a.password == model.Password && a.status == true))
    {
        var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.UserName), }, DefaultAuthenticationTypes.ApplicationCookie);

        this._auth.SignIn(new AuthenticationProperties
        {
            IsPersistent = model.RememberMe
        }, identity);
		
        return RedirectToAction("Index", "Home");
    }
    else
    {
        ModelState.AddModelError("", "Invalid login attempt.");
        return View(model);
    }
}

a Login View and the initial classes of Owin and that’s all. As I said before, No database, not scheme based roles, only the assemblies of OWIN

with the classes already configured.

You can download the source code from github that included the unit tests or you can installed as visual studio extension.

Free Bootstrap Admin Template - SB Admin

To download the extension from the visual studio gallery click here and download the VSIX file install extension

some screenshots

Free Bootstrap Admin Template - SB Admin


Free Bootstrap Admin Template - SB Admin