All of the authentication and authorization process of my app is done using stored procedures. I've written a class with all of functionalities that I need, e.g. GetUsers, Login, AddRole, AddMember, etc.
Also the admin page for managing users and roles and permissions is done by using this class.
I just need to add authentication (I mean that authorize attribute), cookies for Login and Logout and storing some server-side data for each Login. I think I need to implement Identity for that?
In that case, can you please guide me with its implementation? It seems the very basic thing you need to do is to implement a create method that passes an instance of IUserStore to the constructor. But I don't need to have any tables for users or roles, how can I implement this method?
This is the current class, and please let me know if you need to see my custom authentication class that uses stored procedures.
public class AppUserManager : UserManager<AppUser>
{
public AppUserManager(IUserStore<AppUser> store) : base(store) { }
public static AppUserManager Create(IdentityFactoryOptions<AppUserManager> options, IOwinContext context)
{
//AppUserManager manager = new AppUserManager();
//return manager;
return null;
}
}
As alisabzevari suggested you have to implement your IUserStore.
You do not even depend on the storage and table structure defined. You can customize every single bit of your storage layer.
I did some experiments and tried to implement my own
UserManagerandRoleManagerusing a different storage, such as Biggy:You can find the code here on GitHub.
First thing to do is to implement your
UserManagerwhere you can configure the requirements for your password validation:and then define your
IUserStoreimplementation. The main method you must implement isCreateAsync:it will receive an
IUserwhich you have to persist in your custom storage and return it.If you have a look at the code I've implemented you can see I've used a few interfaces
IUserRoleStore,IUserPasswordStore,IUserClaimStoreetc etc as I needed to use roles and claims.I've also implemented my own
SignInManager.Once you've defined all your implementation you can bootstrap everything at startup:
You can check my AccountController where I try to validate the user:
Once
PasswordSignInAsyncis called you will notice a few of the methods of yourUserManagerwill be called. The first one will be FindByNameAsync:You will have to implement your stored procedure, I guess, where you'll fetch your user from the DB.
Then another method
FindByIdAsyncwill be called:Again you'll have to use your stored procedure to find your user by his/her id.
If you download my project from github and play around with it you'll notice that most of those methods will be called multiple times. Don't get scared. That's the way it is.
I would suggest you to insert breakpoints in every single method of the UserStore and see how everything fits together.