Skip to content

Commit

Permalink
basic auth with base64 username:password should be labelled Basic, no…
Browse files Browse the repository at this point in the history
…t Bearer
  • Loading branch information
plumpNation authored and Gavin King committed Apr 11, 2024
1 parent 4672162 commit 11419a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
if (username || password) {
headers = {
...headers,
authorization: `Bearer ${Buffer.from(`${username}:${password}`).toString(`base64`)}`,
authorization: `Basic ${Buffer.from(`${username}:${password}`).toString(`base64`)}`,
};
input.username = input.password = ``;
} else if (input.origin === process.env.COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL) {
Expand All @@ -32,7 +32,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
} else if (`COREPACK_NPM_PASSWORD` in process.env) {
headers = {
...headers,
authorization: `Bearer ${Buffer.from(`${process.env.COREPACK_NPM_USER}:${process.env.COREPACK_NPM_PASSWORD}`).toString(`base64`)}`,
authorization: `Basic ${Buffer.from(`${process.env.COREPACK_NPM_USER}:${process.env.COREPACK_NPM_PASSWORD}`).toString(`base64`)}`,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/_registryServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function generateVersionMetadata(packageName, version) {

const server = createServer((req, res) => {
const auth = req.headers.authorization;
if (!auth?.startsWith(`Bearer `) || Buffer.from(auth.slice(`Bearer `.length), `base64`).toString() !== `user:pass`) {
if (!auth?.startsWith(`Bearer `) || Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`) {
res.writeHead(401).end(`Unauthorized`);
return;
}
Expand Down

0 comments on commit 11419a2

Please sign in to comment.