How to Configure login UI for IdentityServer4?

2019-03-25 05:45发布

问题:

Examples I find for IdentityServer4 use MVC for login UI. When a OpenIdConnect implicit client hits the 'authorization_endpoint' (example 'http://localhost:5000/connect/authorize') it gets redirected to the AccountController Login action. How would you configure IdentityServer4 to use a different controller or UI for as the login page?

回答1:

Under the ConfigureServices method (in Startup) add in a SetupIdentityServer options method:

services.AddIdentityServer(*SetupIdentityServer*)
        .AddSigningCredential(...)
        .AddValidationKeys()
        .AddConfigurationStore(builder => builder.UseSqlServer(""))
        .AddOperationalStore(builder => builder.UseSqlServer(""))
        .AddAspNetIdentity<ApplicationUser>();

...where SetupIdentityServer is the name of a method where you can set the login url:

private static void SetupIdentityServer(IdentityServerOptions identityServerOptions)
{
    identityServerOptions.UserInteraction.LoginUrl = "/Controller/Action";
}