What is the feature you are proposing?
Problem
Bearer auth error responses can't be sent as anything other than application/json or text/plain. The content type is hardcoded in throwHTTPException...
Request
Since we want to adhere to RFC 9457 problem details (application/problem+json) everywhere, it would be nice if we are able to customize the content type in the response. Since the middleware throws an HTTPException with a pre-built res, an onError handler can't fix the headers afterwards either. See for Reference bearer-auth/index.ts
Idea
Let MessageFunction also return a Response and use it as-is (set WWW-Authenticate if missing). Backwards compatible. Alternatively a contentType option next to message (?)
Current workaround: throw from the message function and rebuild the WWW-Authenticate header manually in the app.
What is the feature you are proposing?
Problem
Bearer auth error responses can't be sent as anything other than
application/jsonortext/plain. The content type is hardcoded inthrowHTTPException...Request
Since we want to adhere to RFC 9457 problem details (
application/problem+json) everywhere, it would be nice if we are able to customize the content type in the response. Since the middleware throws anHTTPExceptionwith a pre-builtres, anonErrorhandler can't fix the headers afterwards either. See for Reference bearer-auth/index.tsIdea
Let
MessageFunctionalso return aResponseand use it as-is (setWWW-Authenticateif missing). Backwards compatible. Alternatively acontentTypeoption next tomessage(?)Current workaround: throw from the message function and rebuild the
WWW-Authenticateheader manually in the app.