0

I have a Blazor .Net 5 app using Identity Platform authentication. Out of the box this all works fine, however, I would like to fire my own methods after .Net/AzureAD does it thing, but I am not sure how to best do this.

So the user clicks a "sign in" link, that targets @MicrosoftIdentity/Account/SignIn", MS takes over and handles everything, and return to the callbackPath "/signin-oidc" as per the instructions to set this up. How can I get the following code to run immediately after this process completes?

MyCustomPostSignInLogic()
{
    // All my code to run once, post sign in
}

As an additional ability, is there also a way to intervene .Net automatically sigining the user in, despite them being authenticated?

MyCustomOverrideSignInLogic()
{
   // run this code and perhaps decide not to authenticate a user, despite them successfully completing MS auth.  Maybe we have blacklisted a user, and despite them having a valid MS account, don't want them to specifically authenticate against our app.
}
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
user3280560
  • 137
  • 1
  • 13
  • 1
    You need to use OpenID Connect events. Take a look here: https://stackoverflow.com/questions/51412507/implementing-openidconnectoptions-events-when-using-authentication-azuread-ui-li - I think you specifically want `OnTicketReceived` for both questions here – Camilo Terevinto Sep 07 '21 at 13:46
  • If you'd like to integrate azure ad with your app, I'm afraid that you're unable to add your custom logic to the sign in process. – Tiny Wang Sep 08 '21 at 02:14
  • 1
    @CamiloTerevinto You are bang on the money, this is exactly what I need. OnTicketReceived fires just when needed. I am having trouble with the fact that I require DI to do what I need, but is not available in ConfigureServices (as that is its job), but that is a separate issue. Thanks. – user3280560 Sep 09 '21 at 08:23
  • Glad that I could help! Try to post an answer if you can, it will help others in the future. I already knew about events so searching was easier, but it's not necessarily the case for others (like you :)). – Camilo Terevinto Sep 09 '21 at 12:52

0 Answers0