Search code examples
identityserver4openid-connectidentityserver3

How do you specify SignIn.RequireConfirmedAccount when using AddIdentityExpressAdminUiConfiguration() instead of AddDefaultIdentity()?


I'm using services.AddIdentityExpressAdminUiConfiguration() from the IdentityExpress package. How do I specify SignIn.RequireConfirmedAccount?

Normally this would be accomplished in the services.AddDefaultIdentity() call, but since AddIdentityExpressAdminUiConfiguration() adds the identity, I would end up with an exception if I did that.

Adding the following to ConfigureServices() does not work: services.Configure<SignInOptions>(x => x.RequireConfirmedAccount = true). because UserManager.Options.SignIn.RequireConfirmedAccount is always false.


Solution

  • I accomplished this by adding the following to Configure():

    app.ApplicationServices.GetRequiredService<IOptions<IdentityOptions>>().Value.SignIn.RequireConfirmedAccount = true;

    This will also work for setting the password strength attributes, etc.

    Attempting to set this inside ConfigureServices() didn't work. I suspect it's being overriden by the logic inside AddIdentityExpressAdminUiConfiguration()