Add authentication once again

This commit is contained in:
Laurent
2025-12-10 14:02:40 +01:00
parent 968f05e37b
commit 413c7ee0e5
2 changed files with 11 additions and 6 deletions

View File

@@ -105,13 +105,16 @@
token: token
};
let creds = JSON.parse(localStorage.getItem("creds"));
await fetch("/payment", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(dataToken)
})
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Basic ${creds.username}:${creds.password}`
},
body: JSON.stringify(dataToken)
})
.then(response => {
if (response.ok) {
document.getElementById("paymentAccepted").style.display = 'block';

View File

@@ -8,6 +8,7 @@ import common.json.JsonManager;
import common.logger.Logger;
import common.socket.SocketManager;
import httpServer.annotations.AllowedVerb;
import httpServer.annotations.OnlyAuthorizedClients;
import httpServer.authorization.Client;
import httpServer.authorization.AuthorizedClients;
@@ -40,6 +41,7 @@ public class RequestHandler implements IRequestHandler {
}
@AllowedVerb(name = "POST")
@OnlyAuthorizedClients
public void handlePayment(HttpExchange exchange) {
Logger.displayReceived("/payment request");
try{