auth
auth copied to clipboard
Add custom HTTP handler for authentication errors
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.