Skip to content

Commit 11419a2

Browse files
plumpNationGavin King
authored andcommitted
basic auth with base64 username:password should be labelled Basic, not Bearer
1 parent 4672162 commit 11419a2

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

sources/httpUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
2020
if (username || password) {
2121
headers = {
2222
...headers,
23-
authorization: `Bearer ${Buffer.from(`${username}:${password}`).toString(`base64`)}`,
23+
authorization: `Basic ${Buffer.from(`${username}:${password}`).toString(`base64`)}`,
2424
};
2525
input.username = input.password = ``;
2626
} else if (input.origin === process.env.COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL) {
@@ -32,7 +32,7 @@ async function fetch(input: string | URL, init?: RequestInit) {
3232
} else if (`COREPACK_NPM_PASSWORD` in process.env) {
3333
headers = {
3434
...headers,
35-
authorization: `Bearer ${Buffer.from(`${process.env.COREPACK_NPM_USER}:${process.env.COREPACK_NPM_PASSWORD}`).toString(`base64`)}`,
35+
authorization: `Basic ${Buffer.from(`${process.env.COREPACK_NPM_USER}:${process.env.COREPACK_NPM_PASSWORD}`).toString(`base64`)}`,
3636
};
3737
}
3838
}

tests/_registryServer.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function generateVersionMetadata(packageName, version) {
6666

6767
const server = createServer((req, res) => {
6868
const auth = req.headers.authorization;
69-
if (!auth?.startsWith(`Bearer `) || Buffer.from(auth.slice(`Bearer `.length), `base64`).toString() !== `user:pass`) {
69+
if (!auth?.startsWith(`Bearer `) || Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`) {
7070
res.writeHead(401).end(`Unauthorized`);
7171
return;
7272
}

0 commit comments

Comments
 (0)