I have successfully created a simple MVC 6 application which uses my own ApplicationUser, an ApplicationUserStore (implementing IUserStore and IUserPasswordStore) and ApplicationUserManager (extending UserManager). The login does now work perfectly. Now I do want to extend my project to support annotations in my controllers like the following:
[Authorize(Roles = "TestRole")]
public IActionResult Trips()
{
...
}
Therefore I have also created my own ApplicationRole, ApplicationRoleManager, ApplicationRoleStore and registered them in my Startup:
services.AddIdentity<ApplicationUser, ApplicationRole>(config =>
{
config.User.RequireUniqueEmail = true;
config.Password.RequiredLength = 8;
config.Cookies.ApplicationCookie.LoginPath = "/Auth/Login";
config.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
}).AddUserStore<ApplicationUserStore<ApplicationUser>>()
.AddRoleStore<ApplicationRoleStore<ApplicationRole>>()
.AddUserManager<ApplicationUserManager>()
.AddRoleManager<ApplicationRoleManager>();
My problem is now that the annotation does not work at all. Actually I hoped that somehow the Roles method (from IQueryableRoleStore) in my ApplicationRoleStore would be fired.
Do I miss somewhere I binding or do I have a complete wrong idea of the identity/role concept?