Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ext auth #408

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ The complete list of configurable parameters that can be configured via `userale
| transmitInterval | Delay between transmit checks | 5000 (ms) |
| logCountThreshold | Minimum number of logs to send | 5 |
| userId | User identifier | null |
| password | Used with userId for basic authentication auth header, overwritten by authHeader | null |
| sessionID | Session identifier | null |
| version | Application version identifier | null |
| logDetails | Toggle detailed logs (keys pressed and input/change values) | false |
Expand Down Expand Up @@ -161,6 +162,7 @@ You have access to the same parameters listed above, however, naming conventions
| data-interval | Delay between transmit checks | 5000 (ms) |
| data-threshold | Minimum number of logs to send | 5 |
| data-user | User identifier | null |
| data-password | Used with user for basic authentication auth header, overwritten by auth | null |
| data-version | Application version identifier | null |
| data-log-details | Toggle detailed logs (keys pressed and input/change values) | false |
| data-resolution | Delay between instances of high frequency logs (mouseover, scroll, etc.) | 500 (ms) |
Expand Down
15 changes: 10 additions & 5 deletions build/UserALEWebExtension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function getInitialSettings() {
settings.transmitInterval = +get('data-interval') || 5000;
settings.logCountThreshold = +get('data-threshold') || 5;
settings.userId = get('data-user') || null;
settings.password = get('data-password') || null;
settings.version = get('data-version') || null;
settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
Expand Down Expand Up @@ -986,6 +987,11 @@ function sendLogs(logs, config, retries) {
var req = new XMLHttpRequest();
var data = JSON.stringify(logs);
req.open("POST", config.url);

// Update headers
if (config.userId && config.password) {
req.setRequestHeader("Authorization", "Basic " + btoa("".concat(config.userId, ":").concat(config.password)));
}
if (config.authHeader) {
req.setRequestHeader("Authorization", config.authHeader);
}
Expand Down Expand Up @@ -1144,15 +1150,14 @@ function dispatchTabMessage(message) {
}
browser.runtime.onMessage.addListener(function (message) {
switch (message.type) {
case CONFIG_CHANGE:
options(message.payload);
dispatchTabMessage(message);
break;

// Handles logs rerouted from content and option scripts
case ADD_LOG:
log(message.payload);
break;
case CONFIG_CHANGE:
options(message.payload);
dispatchTabMessage(message);
break;
default:
console.log('got unknown message type ', message);
}
Expand Down
7 changes: 6 additions & 1 deletion build/UserALEWebExtension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function getInitialSettings() {
settings.transmitInterval = +get('data-interval') || 5000;
settings.logCountThreshold = +get('data-threshold') || 5;
settings.userId = get('data-user') || null;
settings.password = get('data-password') || null;
settings.version = get('data-version') || null;
settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
Expand Down Expand Up @@ -1000,6 +1001,11 @@ function sendLogs(logs, config, retries) {
var req = new XMLHttpRequest();
var data = JSON.stringify(logs);
req.open("POST", config.url);

// Update headers
if (config.userId && config.password) {
req.setRequestHeader("Authorization", "Basic " + btoa("".concat(config.userId, ":").concat(config.password)));
}
if (config.authHeader) {
req.setRequestHeader("Authorization", config.authHeader);
}
Expand Down Expand Up @@ -1100,7 +1106,6 @@ function options(newConfig) {
// browser is defined in firefox, but chrome uses the 'chrome' global.
var browser = browser || chrome;
function rerouteLog(log) {
console.log(log);
browser.runtime.sendMessage({
type: ADD_LOG,
payload: log
Expand Down
9 changes: 8 additions & 1 deletion build/UserALEWebExtension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function getInitialSettings() {
settings.transmitInterval = +get('data-interval') || 5000;
settings.logCountThreshold = +get('data-threshold') || 5;
settings.userId = get('data-user') || null;
settings.password = get('data-password') || null;
settings.version = get('data-version') || null;
settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
Expand Down Expand Up @@ -1000,6 +1001,11 @@ function sendLogs(logs, config, retries) {
var req = new XMLHttpRequest();
var data = JSON.stringify(logs);
req.open("POST", config.url);

// Update headers
if (config.userId && config.password) {
req.setRequestHeader("Authorization", "Basic " + btoa("".concat(config.userId, ":").concat(config.password)));
}
if (config.authHeader) {
req.setRequestHeader("Authorization", config.authHeader);
}
Expand Down Expand Up @@ -1100,7 +1106,6 @@ function options(newConfig) {
// browser is defined in firefox, but chrome uses the 'chrome' global.
var browser = browser || chrome;
function rerouteLog(log) {
console.log(log);
browser.runtime.sendMessage({
type: ADD_LOG,
payload: log
Expand Down Expand Up @@ -1135,6 +1140,7 @@ function setConfig(e) {
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
}
Expand All @@ -1147,6 +1153,7 @@ function getConfig() {
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);
Expand Down
10 changes: 5 additions & 5 deletions build/UserALEWebExtension/optionsPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
<body>
<h1>Options</h1>
<form>
<label>User ALE Server Host:</label>
<label>Logging Endpoint URL:</label>
<input id="url"/>
<br/>

<label>User ALE Client Script:</label>
<input id="clientScript"/>
<br/>

<label>User:</label>
<input id="user"/>
<br/>

<label>Password:</label>
<input type="password" id="password"/>
<br/>

<label>Tool Name:</label>
<input id="tool"/>
<br/>
Expand Down
4 changes: 4 additions & 0 deletions build/userale-2.4.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
settings.transmitInterval = +get('data-interval') || 5000;
settings.logCountThreshold = +get('data-threshold') || 5;
settings.userId = get('data-user') || null;
settings.password = get('data-password') || null;
settings.version = get('data-version') || null;
settings.logDetails = get('data-log-details') === 'true' ? true : false;
settings.resolution = +get('data-resolution') || 500;
Expand Down Expand Up @@ -1162,6 +1163,9 @@
req.open("POST", config.url);

// Update headers
if (config.userId && config.password) {
req.setRequestHeader("Authorization", "Basic " + btoa("".concat(config.userId, ":").concat(config.password)));
}
updateAuthHeader(config);
if (config.authHeader) {
req.setRequestHeader("Authorization", config.authHeader);
Expand Down
Loading
Loading