Search code examples
oauthoauth-2.0identityserver4openidasp.net-core-3.1

Handling callback from Identity Server


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 ?


Solution

  • 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;
        },
    };