Set auth header with password
diff --git a/build/UserALEWebExtension/background.js b/build/UserALEWebExtension/background.js
index f844a93..d9372d0 100644
--- a/build/UserALEWebExtension/background.js
+++ b/build/UserALEWebExtension/background.js
@@ -1149,6 +1149,7 @@
log(message.payload);
break;
case CONFIG_CHANGE:
+ console.log(message);
options(message.payload);
dispatchTabMessage(message);
break;
diff --git a/build/UserALEWebExtension/options.js b/build/UserALEWebExtension/options.js
index a075371..acd305a 100644
--- a/build/UserALEWebExtension/options.js
+++ b/build/UserALEWebExtension/options.js
@@ -1129,27 +1129,22 @@
addCallbacks({
reroute: rerouteLog
});
-function setConfig(e) {
+function setConfig() {
+ var config = {
+ url: document.getElementById("url").value,
+ userId: document.getElementById("user").value,
+ toolName: document.getElementById("tool").value,
+ version: document.getElementById("version").value
+ };
+
+ // Set a basic auth header if given credentials.
+ var password = document.getElementById("password").value;
+ if (config.userId && password) {
+ config.authHeader = "Basic " + btoa("".concat(config.userId, ":").concat(password));
+ }
browser.storage.local.set({
- useraleConfig: {
- url: document.getElementById("url").value,
- userId: document.getElementById("user").value,
- password: document.getElementById("password").value,
- toolName: document.getElementById("tool").value,
- version: document.getElementById("version").value
- }
+ useraleConfig: config
}, function () {
- getConfig();
- });
-}
-function getConfig() {
- browser.storage.local.get("useraleConfig", function (res) {
- var config = res.useraleConfig;
- document.getElementById("url").value = config.url;
- document.getElementById("user").value = config.userId;
- document.getElementById("password").value = config.password;
- document.getElementById("tool").value = config.toolName;
- document.getElementById("version").value = config.version;
options(config);
browser.runtime.sendMessage({
type: CONFIG_CHANGE,
@@ -1157,7 +1152,17 @@
});
});
}
-document.addEventListener('DOMContentLoaded', getConfig);
+function getConfig() {
+ browser.storage.local.get("useraleConfig", function (res) {
+ var config = res.useraleConfig;
+ options(config);
+ document.getElementById("url").value = config.url;
+ document.getElementById("user").value = config.userId;
+ document.getElementById("tool").value = config.toolName;
+ document.getElementById("version").value = config.version;
+ });
+}
+document.addEventListener("DOMContentLoaded", getConfig);
document.addEventListener("submit", setConfig);
/* eslint-enable */
diff --git a/src/UserALEWebExtension/background.js b/src/UserALEWebExtension/background.js
index 99f1523..5987938 100644
--- a/src/UserALEWebExtension/background.js
+++ b/src/UserALEWebExtension/background.js
@@ -51,6 +51,7 @@
break;
case MessageTypes.CONFIG_CHANGE:
+ console.log(message);
userale.options(message.payload);
dispatchTabMessage(message);
break;
diff --git a/src/UserALEWebExtension/options.js b/src/UserALEWebExtension/options.js
index 2207ed3..b2ecbdb 100644
--- a/src/UserALEWebExtension/options.js
+++ b/src/UserALEWebExtension/options.js
@@ -22,36 +22,42 @@
userale.addCallbacks({reroute: rerouteLog});
-function setConfig(e) {
- browser.storage.local.set(
- {useraleConfig: {
- url: document.getElementById("url").value,
- userId: document.getElementById("user").value,
- password: document.getElementById("password").value,
- toolName: document.getElementById("tool").value,
- version: document.getElementById("version").value
- }},
- () => {getConfig()}
- );
+// TODO: Warn users when setting credentials with unsecured connection.
+const mitmWarning = "Setting credentials with http will expose you to a MITM attack. Are you sure you want to continue?";
+
+function setConfig() {
+ let config = {
+ url: document.getElementById("url").value,
+ userId: document.getElementById("user").value,
+ toolName: document.getElementById("tool").value,
+ version: document.getElementById("version").value
+ };
+
+ // Set a basic auth header if given credentials.
+ const password = document.getElementById("password").value;
+ if(config.userId && password) {
+ config.authHeader = "Basic " + btoa(`${config.userId}:${password}`);
+ }
+
+ browser.storage.local.set({useraleConfig: config}, () => {
+ userale.options(config);
+ browser.runtime.sendMessage({ type: MessageTypes.CONFIG_CHANGE, payload: config });
+ });
}
function getConfig() {
browser.storage.local.get("useraleConfig", (res) => {
let config = res.useraleConfig;
+ userale.options(config);
document.getElementById("url").value = config.url;
document.getElementById("user").value = config.userId;
- document.getElementById("password").value = config.password;
document.getElementById("tool").value = config.toolName;
document.getElementById("version").value = config.version;
-
- userale.options(config);
- browser.runtime.sendMessage({ type: MessageTypes.CONFIG_CHANGE, payload: config });
-
});
}
-document.addEventListener('DOMContentLoaded', getConfig);
+document.addEventListener("DOMContentLoaded", getConfig);
document.addEventListener("submit", setConfig);
/* eslint-enable */
\ No newline at end of file