How to set custom error message in IdentityServer 4?

Viewed 1614

I am trying to customise the error messages returned by IdentityServer 4. I am running a .NET Core 2.2 app. Looking in the docs I added the following bit:

services
    .AddIdentityServer()
    // other stuff
    .AddCustomTokenRequestValidator<TestValidator>();

...

public class TestValidator : ICustomTokenRequestValidator
{
    public Task ValidateAsync(CustomTokenRequestValidationContextcontext)
    {
        var validationResult = context.Result;

        validationResult.ErrorDescription = ":D";

        return Task.CompletedTask;
    }
}

The problem is that when I set a breakpoint in the ValidateAsync method, the breakpoint is never triggered. What I'd like to do is when a user inputs an invalid set of client id/secret to return a custom message, instead of the generic error: invalid_client.

To request a token I use the following in my other project:

var token = await httpClient.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest {...});
0 Answers
Related