1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3236 from hardillb/http-basic-username-only

HTTP Basic Auth should always add : between username and password even if empty
This commit is contained in:
Nick O'Leary 2021-10-28 10:14:02 +01:00 committed by GitHub
commit e6de52eede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -298,18 +298,14 @@ in your Node-RED user directory (${RED.settings.userDir}).
} }
if (Object.keys(this.credentials).length != 0) { if (Object.keys(this.credentials).length != 0) {
if (this.authType === "basic") { if (this.authType === "basic") {
// Workaround for https://github.com/sindresorhus/got/issues/1169 // Workaround for https://github.com/sindresorhus/got/issues/1169 (fixed in got v12)
var cred = "" // var cred = ""
if (this.credentials.user) { if (this.credentials.user || this.credentials.password) {
// opts.username = this.credentials.user; // cred = `${this.credentials.user}:${this.credentials.password}`;
cred = this.credentials.user opts.headers.Authorization = "Basic " + Buffer.from(`${this.credentials.user}:${this.credentials.password}`).toString("base64");
}
if (this.credentials.password) {
// opts.password = this.credentials.password;
cred += ":" + this.credentials.password
} }
// build own basic auth header // build own basic auth header
opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); // opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64");
} else if (this.authType === "digest") { } else if (this.authType === "digest") {
let digestCreds = this.credentials; let digestCreds = this.credentials;
let sentCreds = false; let sentCreds = false;