Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏭 Add BasicAuth addon #223

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

BendingBender
Copy link

@BendingBender BendingBender commented Mar 11, 2024

Implement BasicAuth addon that adds following behaviors:

  • allows setting credentials via the .basicAuth() method
  • parses URLs and extracts credentials from them, converting them to an Authorization header and removing them from the URL which would otherwise throw an error when passed to native fetch()
  • correctly encodes usernames/passwords that contain non-latin characters (see https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem)

Fixes #221

Implement BasicAuth addon that adds following behaviors:
- allows setting credentials via the `.basicAuth()` method
- parses URLs and extracts credentials from them, converting them to an Authorization header and removing them from the URL which would otherwise throw an error when passed to native fetch()
- correctly parses usernames/passwords that contain non-latin characters (see https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem)
@BendingBender
Copy link
Author

I have a question here: I also use the encodeURIComponent and btoa globals in my addon. Should I inject them via the polyfill system, just like URL and TextEncoder or do you think that this is the absolute baseline that doesn't need polyfilling?

@ChiliBoyRed
Copy link

I have a question here: I also use the encodeURIComponent and btoa globals in my addon. Should I inject them via the polyfill system, just like URL and TextEncoder or do you think that this is the absolute baseline that doesn't need polyfilling?

If you intend to make this compatible with React Native, it doesn't support atob or btoa (yet) other than through polyfills.

@BendingBender
Copy link
Author

I have a question here: I also use the encodeURIComponent and btoa globals in my addon. Should I inject them via the polyfill system, just like URL and TextEncoder or do you think that this is the absolute baseline that doesn't need polyfilling?

If you intend to make this compatible with React Native, it doesn't support atob or btoa (yet) other than through polyfills.

This should already work in any environment that has native btoa or has it already polyfilled globally. So the question is actually whether we need to support local polyfills (i.e. only for this lib). I don't use RN and have no experience with it. Can you tell me whether it's common to globally polyfill btoa there?

Copy link
Owner

@elbywan elbywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 👍 Excellent work, thanks a bunch for this PR! And really sorry for not reviewing earlier (I have been quite busy these last 2 months).

I just have a couple of comments regarding polyfills:

  • polyfilling URL / TextEncoder is not strictly necessary since the minimum level of support we are aiming for is node 14 which includes both out of the box
  • I'm fine with not polyfilling btoa / atob, regarding react native it seems like they are already supporting it (or will be very soon): Add support for atob() and btoa() functions facebook/hermes#1178

@elbywan elbywan changed the base branch from master to dev May 11, 2024 09:23
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.

Basic auth middleware/extension
3 participants