auth icon indicating copy to clipboard operation
auth copied to clipboard

Add custom HTTP handler for authentication errors

Open cyb3r4nt opened this issue 6 months ago • 4 comments

This patch gives a possibility to configure custom HTTP handlers, which can change the default authentication error responses in the middlewares.

The default implementation uses http.Error() method, which produces content type text/plain and simple textual messages rendered directly into the response body. In some applications this behavior may not be enough, and there may be a need to produce different responses like JSON or HTML. The AuthErrorHTTPHandler interface allows to intercept authentication errors and write HTTP responses according to specific application requirements.

I also added some additional middleware methods, which allow to configure different AuthErrorHTTPHandler implementations for different HTTP routes. Some routes in the applications may require different response bodies or attributes.

cyb3r4nt avatar Aug 02 '24 17:08 cyb3r4nt