Identity Server 4 : Sorry, there was an error : unauthorized_client

I found out this was due to the RedirectUris being incorrect.

This error is thrown if there is anything wrong with the client.


I tried using https instead of http to access my local sitecore admin panel like this

https://site.local/sitecore and it worked remember its only https !


The cause may be RedirectUris of a client do not include the actual redirect uri the client app is sending. This is configured in Client.cs method GetClients:

new Client
{
    ...
    RedirectUris = new[] { "https://..." }, 
    PostLogoutRedirectUris = new[] { "https://..." },
    AllowedCorsOrigins = new[] { "https://..." },
}

The redirect URI must match exactly the address the client is sending, including the HTTP scheme (http, https).

This can be found in log the file that lists allowed URIs and the actual URI of a failed authorization request. Identity server is using serilog, in program.cs it can be switched on in Main method:

...

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
    .MinimumLevel.Override("System", LogEventLevel.Warning)
    .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
    .Enrich.FromLogContext()
    .WriteTo.File("logs\\the-log-file-name.txt")
    .CreateLogger();

BuildWebHost(args).Run();