user3900456 user3900456 - 3 months ago 34
ASP.NET (C#) Question

How to use OWIN forms authentication without aspnet identity

I want to use the OWIN pipeline to emit the authentication cookie to the client, clear the cookie when the user signs out etc but I don`t want to use the annoying aspnet identity provider. It just doesn't fit on the project, I tried for a long time and it just doesn't fit. So I decide I won't use it. I just want to use the OWIN pipeline.

Is this possible or I should fall back to the old forms authentication?

Answer

Like this?

var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "Brock"));
claims.Add(new Claim(ClaimTypes.Email, "brockallen@gmail.com"));
var id = new ClaimsIdentity(claims,
                            DefaultAuthenticationTypes.ApplicationCookie);

var ctx = Request.GetOwinContext();
var authenticationManager = ctx.Authentication;
authenticationManager.SignIn(id);

Taken from here.