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

Merged
merged 4 commits into from
Jun 1, 2024
Merged

🏭 Add BasicAuth addon #223

merged 4 commits into from
Jun 1, 2024

Conversation

BendingBender
Copy link
Contributor

@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

@BendingBender
Copy link
Contributor 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?

@ghost
Copy link

ghost commented Apr 28, 2024

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
Contributor 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
@BendingBender
Copy link
Contributor Author

Just a small note: I use URL.canParse() which is supported since node 18.17 (according to MDN). This means that strictly speaking, polyfilling URL will be necessary on node 14. Should I stop using the polyfill system for the TextEncoder?

@elbywan
Copy link
Owner

elbywan commented May 16, 2024

I use URL.canParse() which is supported since node 18.17 (according to MDN).

Oh sorry I did not get that 👍.

Should I stop using the polyfill system for the TextEncoder?

Yes I think using the global TextEncoder would be fine.

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
Contributor Author

Done

@coveralls
Copy link

Coverage Status

coverage: 87.213% (+0.08%) from 87.137%
when pulling 57f46f2 on BendingBender:feature/basic-auth
into b299791 on elbywan:dev.

@elbywan elbywan merged commit 97773d0 into elbywan:dev Jun 1, 2024
10 checks passed
@BendingBender BendingBender deleted the feature/basic-auth branch June 4, 2024 18:07
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