I've implemented an api key auth for my .net core api, and if an invalid key is found I return the following as mentioned in a tutorial:
return AuthenticateResult.Fail("Invalid API Key provided.");
This seems to result in my override of HandleChallengeAsync being called:
protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
{
Response.StatusCode = 401;
Response.ContentType = ProblemDetailsContentType;
var problemDetails = new UnauthorizedProblemDetails();
await Response.WriteAsync(JsonSerializer.Serialize(problemDetails));
}
I'm confused of the purpose of passing the fail reason to the .Fail() call, as it doesn't seem available for me to return to the user. What is it for?