Update templates/main.html

This commit is contained in:
Tracker-Friendly 2024-04-18 13:03:05 +01:00
parent a703889319
commit 9a0806aa1c
1 changed files with 7 additions and 26 deletions

View File

@ -31,6 +31,8 @@
if (urlParams.has('state')) { if (urlParams.has('state')) {
var state = urlParams.get('state'); var state = urlParams.get('state');
} else {
state = "none"
} }
if (urlParams.has('code_challenge')) { if (urlParams.has('code_challenge')) {
@ -43,34 +45,13 @@
// Get DONOTSHARE-secretkey from localStorage // Get DONOTSHARE-secretkey from localStorage
var secret_key = localStorage.getItem("DONOTSHARE-secretkey"); var secret_key = localStorage.getItem("DONOTSHARE-secretkey");
var now = new Date();
// Create data object to send var expireTime = now.getTime() + (21 * 1000); // 21 seconds from now
var data = { var expires = new Date(expireTime).toUTCString();
appId: client_id, document.cookie = "cookieName=cookieValue; expires=" + expires + "; path=/";
secretKey: secret_key,
code: code,
codemethod: codemethod
};
// Send data to example.org using POST request // Send data to example.org using POST request
fetch("https://auth.hectabit.org/api/auth", { window.location.replace("/api/auth?client_id=" + client_id + "&redirect_uri=" + redirect_uri + "&code_challenge_method=" + codemethod + "&code_challenge=" + code + "&state=" state)
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => {
async function doStuff() {
let code = await response.text()
console.log(code)
window.location.replace(redirect_uri + "?code=" + code + "&state=" + state)
}
doStuff()
})
.catch(error => {
alert("Error sending data: " + error.message);
});
} }
oauth() oauth()
</script> </script>