How to add custom logic to ASP.NET CORE 6 Identity sign-in

Viewed 504

I'm trying to wrap my head around how Identity works, and how to customize it.

I have an existing DB and website (asp.net, not core), and then the new system (asp.net core v6). I don't want to use EF so I've implemented custom IUserStore/IUserPasswordStore/IUserEmailStore/etc.

Situation: I have some custom code (in SQL/stored-proc) that the old system runs on sign-in, which checks certain domain-specific data (eg User.IsHappy = 1 AND User.NumTimesTheyWereNiceToMe > 3), as well as creating sign-in records (ie INSERT INTO UserSignedIn...). I need to do the same thing in the new system (using Identity).

Issue: Where do I run my custom query? In the old system I didn't use Identity, so I just called the stored-proc (which checks credentials/data/etc, creates signedin record, and returns signin result) and then I'd create auth cookie/etc.

With Identity I'm guessing I should override SignInManager.PreSignInCheck to check the user data as needed (and customize IUserStore to pull that data), and also override SignInManager.CheckPasswordSignInAsync and if base.CheckPasswordSignInAsync returns success then make a separate call to the DB in order to insert my UserSignedIn record?

Is this the correct approach, or is there a more sensible way? Thanks for any help.

0 Answers
Related