Skip to content

Write custom authentication failure information to the response body #44100

@AlexandreBossard

Description

@AlexandreBossard

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I have written my Authentication Handler (loosely based on JwtBearHandler). Obviously, I have some AuthenticateResult.fail(ex). All that is good. But, I would like to extract info from these errors and translate them to the Response body aside from the expected 401.

Outside the authentication / authentication framework, I've written an exception handler that does exactly that for controllers.

Unfortunately, I've failed to find a way to retrieve the AuthenticateResult produced by the authentication Handler. IAuthorizationMiddlewareResultHandler do expose the AuthenticateResult but not when the authentication fails, only when it succeed, through HttpContext.Features.Get<IAuthenticateResultFeature>().

Describe the solution you'd like

I would like some ways to get the AuthenticationResult and generate a response body from it. I suppose I could do that from the IAuthorizationMiddlewareResultHandler assuming I had access to the result, regardless of the authentication state. I would throw from the resultHandler which would be translated by the exception handler.

Or am I missing something here ? Any Documentation to point me to ?

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authIncludes: Authn, Authz, OAuth, OIDC, Bearer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions