Skip to content

Feature Request: Bearer Auth - allow custom error response content type #5218

Description

@max-got

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions