0

As a client app, user logged in from Identity server and redirected to /signin-oidc endpoint the the client app. /signin-oidc is handled automatically by OpenId middleware already so i can not put my registration user process at first login.

On external login process in the case of Google, Facebook or Microsoft, there was a returnUrl redirection at the end of successful login and i was able to inject my registration(saving user details) code logic.

It seems OpenId is different on this aspect. So what is right way to registration process ?

Freshblood
  • 6,285
  • 10
  • 59
  • 96

1 Answers1

1

You can use notification events in OIDC OWIN Middlerware which invokes to enable developer add custom logic . For example, you can query the database and create a user in OnTokenValidated event :

options.Events = new OpenIdConnectEvents
{
    OnTokenValidated = ctx =>
    {
        //query the database 

        var db = ctx.HttpContext.RequestServices.GetRequiredService<YourDbContext>();

        //perform custom logic for user management in local database


        return Task.CompletedTask;
    },
};
Nan Yu
  • 26,101
  • 9
  • 68
  • 148
  • I wouldn't like to access service locator so i my preference would be handle it inside controller but i guess this is only way to do that. – Freshblood May 11 '20 at 08:18
  • If you want do that in controller , you can manually set the path : `if (!User.Identity.IsAuthenticated) { return Challenge(new AuthenticationProperties() { RedirectUri = "/home/redirectOnRole" } , AzureADDefaults.AuthenticationScheme); }` , see https://stackoverflow.com/a/61452853/5751404 . Change scheme name based on your authentication scheme – Nan Yu May 11 '20 at 08:50
  • Or you can do that in index page , since by default , the oidc middleware will back to index page after authentication . – Nan Yu May 11 '20 at 08:51