WebUI: Use Authentication header instead of URL

This commit is contained in:
Max Berger
2026-03-22 16:16:27 +01:00
parent 07685c292f
commit e0017c9bf0
3 changed files with 69 additions and 10 deletions

View File

@@ -32,6 +32,18 @@ export function to_error_message(request) {
return request.status + " " + request.statusText;
}
/**
* @param {?string} user
* @param {?string} password
* @returns {?string}
*/
export function get_auth_header(user, password) {
if (user !== null && password !== null && password !== "") {
return 'Basic ' + btoa(user + ':' + encodeURIComponent(password));
}
return null;
}
/**
* @param {string} method
* @param {string} url
@@ -41,10 +53,10 @@ export function to_error_message(request) {
*/
export function create_request(method, url, user, password) {
let request = new XMLHttpRequest();
if (user !== null && password !== null) {
request.open(method, url, true, user, encodeURIComponent(password));
} else {
request.open(method, url, true);
request.open(method, url, true);
let auth = get_auth_header(user, password);
if (auth !== null) {
request.setRequestHeader('Authorization', auth);
}
return request;
}