I have just started to know the MVC 5 and I am trying to use its built in owin authentication.
I need to implement a forms authentication with IIS, but the OWIN Authentication is complicated than i waited.
I have az Entity Framework Model with own User, Role and RoleUser tables and want to authenticate user by these tables.
I tried to figured it out, how the owin works on a sample mvc 5 application. It has an ApplicationUser class:
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
My main problem is the IdentityUser. It is an own ASP.NET User class with implementation of IUser interface and connection of DbContext. I have an own User POCO entity from the EF model and i do not want to mix it with an ASP.NET IUser interface. I do know why, but the Id of IUser interface is string type, that is also not apply to me.
The owin async user sign in is the following:
private async Task SignInUserAsync(User user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
ClaimsIdentity identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
It recommends to create a ClaimsIdentity type of identity to sign in user and the user property must implements IUser interface.
Big question: Is the owen suggested to use in my environment? I want to use my User Class with owin authentication, but i don't know how?
Thanks your help in advance!