Skip to content

Conversation

@Phillip9587
Copy link

Currently, the basic-auth package supports parsing Authorization headers from Node.js IncomingMessage objects. However, with the increasing usage of the Fetch API in modern applications (both in server-side environments like Deno, Cloudflare Workers, and Bun, as well as in edge functions), it would be beneficial to extend support to the Fetch API Request interface.

Use Case

In environments like Cloudflare Workers, Deno, and other serverless platforms, request objects conform to the Fetch API standard rather than the Node.js IncomingMessage format. Supporting Request objects would enable seamless authentication handling in these environments without the need for manual header extraction.

Proposed Solution

Modify basic-auth to accept both IncomingMessage and Fetch API Request objects. The implementation could check for the presence of req.headers.get('authorization') in addition to req.headers['authorization'] (Node.js style).

Alternative Workarounds

Currently, users working with Fetch API-based environments must manually extract the Authorization header before passing it to basic-auth, which adds extra steps and reduces convenience:

const credentials = auth.parse(request.headers.get('authorization'));

Adding native support would improve DX (developer experience) and make basic-auth more flexible for modern runtimes.

@Phillip9587 Phillip9587 mentioned this pull request Feb 12, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant