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

View File

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