Search code examples
c#asp.net-coreidentityserver4

How can I override the default error path in Identity Server 4?


I have an Identity Server 4 implementation where I'm migrating the UI from ASP.NET MVC to a decoupled React app. The problem I have is that when Identity Server handles an error (such as an invalid client) it redirects to /home/error?errorId=<error-id> using, I assume, the path defined in a constant here. I would like to customise this error path so it matches a route in my React app. Any idea how to do this? The nearest I've found to an answer is here on Github where the OP asks if there are plans to make these constants customisable, and Brock Allen replies "Yep"! That was 2016 😁


Solution

  • There's an overload of AddIdentityServer that you can use to configure the IdentityServerOptions that gets used by IdentityServer. Here's an example that sets the ErrorUrl property:

    services.AddIdentityServer(options =>
    {
        options.UserInteraction.ErrorUrl = "/path/to/error";
    })