I just watched a video from Scott Allen to learn more about MVC 5 Identity on ASP.NET. By the way the video is a great resource to get a grasp of the fundamentals of ASP.NET MVC 5. I’m primarily interested on Identity, OWIN and Katana because I just brushed through them quickly while working on a team project before. I should really start posting stuff I learned during the day or during the course of a week. I think in addition to writing code and building something, writing about it helps in making it stick 🙂
This is new in MVC 5, the core assembly of MVC 5 provides interfaces that you can implement if you want full control of user creation, authentication, etc. in your application. But I think Microsoft’s implementation is good for most projects.
Microsoft’s implementation relies on Entity Framework to talk with a SQL Server Db. If you want to use a different database, implement the interface provided. The diagram below is a quick overview of what I think are the most important core interfaces:
Microsoft is using a repository pattern on this one, the implementation will be hiding behind interfaces which I believe is a good thing. The concrete class UserManager is there to manage users. IUserStore and its buddies – IUserLoginStore and IUserPasswordStore, who also implements IUserStore – has methods for database access. The Role interface by the way uses the same pattern as the User interface. It has store interfaces for database access.
Reiterating this, a User or Role just holds your data. UserStore etc. puts this on a Database of your choice. You then use the UserManager concrete class to orchestrate, it has your domain logic. Unless you have to do something low level.
This is one implementation of the core interfaces above. Entity Framework has IdentityUser, IdentityRole, a UserStore class, which I think are the crucial ones. The UserStore class implements IUserStore, IUserLogin and IUserPassword. To talk with SQL Server, it has IdentityDbContext. In conclusion, use this unless you really need some custom implementation. Also, I suggest watching this video since it is awesome 🙂