Skip to content

feat: add auth.format for formatting credentials#65

Open
Phillip9587 wants to merge 5 commits intojshttp:masterfrom
Phillip9587:format
Open

feat: add auth.format for formatting credentials#65
Phillip9587 wants to merge 5 commits intojshttp:masterfrom
Phillip9587:format

Conversation

@Phillip9587
Copy link
Copy Markdown
Contributor

This pull request introduces a new feature to the basic-auth library, adding a method to format credentials into a basic auth header string.

Comment thread index.js Outdated
@Phillip9587
Copy link
Copy Markdown
Contributor Author

@blakeembrey I rebased and added your suggestions to disallow colons in username and control characters in both username and password.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (08b56ca) to head (9994571).

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #65   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           21        60   +39     
  Branches         6        22   +16     
=========================================
+ Hits            21        60   +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Phillip9587
Copy link
Copy Markdown
Contributor Author

Maybe we should merge this before #95 so that i can also add a cross-environment encodeBase64() in #95.

* master:
  Update docs to use `parse` method (jshttp#97)
* master:
  Improve parse perf with benchmarks (jshttp#96)
Comment thread src/index.ts
);
}

if (credentials.name.length === 0 || credentials.pass.length === 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see anything requiring these to be non-empty, we should probably allow it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

RFC 7613, Section 3.1 states:

A username MUST NOT be zero bytes in length. This rule is to be enforced after any normalization and mapping of code points.

RFC 7613, Section 4.1 states:

A password MUST NOT be zero bytes in length. This rule is to be enforced after any normalization and mapping of code points.

If you think we should not enforce it I'm fine with it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. I didn't see it in the specs for authentication, and the original basic auth specification said it was 0 or more characters. I think we should still remove it because that specification deviates further from allowed characters than just control characters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://www.rfc-editor.org/rfc/rfc2617:

  user-pass   = userid ":" password
  userid      = *<TEXT excluding ":">
  password    = *TEXT

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See #55

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I saw that too but didn’t see any suggestion to disallow empty unless I overlooked it?

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread src/index.ts

if (
typeof credentials.name !== 'string' ||
typeof credentials.pass !== 'string'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm happy to get rid of all the safety checks in the new major, but can do it in a follow up PR instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why remove them?

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.

2 participants