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: master
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?

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
2 participants