use Bearer auth instead of Basic

this was a relic from the python version, i'd modeled the auth code off
some random blog post back then.
This commit is contained in:
Harvey Tindall
2020-11-12 21:04:35 +00:00
parent ba601935b5
commit d64e98da37
6 changed files with 147 additions and 157 deletions
+9 -2
View File
@@ -121,8 +121,15 @@ window.toClipboard = (str: string): void => {
function login(username: string, password: string, modal: boolean, button?: HTMLButtonElement, run?: (arg0: number) => void): void {
const req = new XMLHttpRequest();
req.responseType = 'json';
req.open("GET", "/getToken", true);
req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
let url = "/token/login";
const refresh = (username == "" && password == "");
if (refresh) {
url = "/token/refresh";
}
req.open("GET", url, true);
if (!refresh) {
req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
}
req.onreadystatechange = function (): void {
if (this.readyState == 4) {
if (this.status != 200) {