mirror-chatterino2/resources/auth.html

57 lines
1.9 KiB
HTML
Raw Normal View History

<html>
<head>
<title>Login - Chatterino</title>
</head>
2021-07-24 13:36:06 +02:00
<body>
<noscript>
<p>noscript stuffs here</p>
</noscript>
<p id="status">Loading...</p>
<script>
2021-07-24 13:36:06 +02:00
(function() {
// Address of local Chatterino's http server
const address = "localhost";
const port = 52107;
// Retrieve hash with token and hide it immidiatelly
const fragment = location.hash.substring(1);
history.replaceState(null, null, " ");
// Find token in the hash
2021-07-24 13:36:06 +02:00
const token = new URLSearchParams(fragment).get("access_token");
let status = document.getElementById("status");
// Return if no token was found
2021-07-24 13:36:06 +02:00
if (!token) {
status.innerHTML = "Bad request";
return;
}
// Call Chatterino's http server
status.innerHTML = "Sending your credentials to Chatterino...";
fetch(`http://${address}:${port}/token`, {
2021-07-24 13:36:06 +02:00
method: "PUT",
headers: {
"X-Access-Token": token
}
}).then(resp => {
// Failure
if (resp.status !== 200) {
status.innerHTML = `Chatterino refused your credentials, error ${resp.status}`;
return;
}
// Success
status.innerHTML = "Chatterino added your account successfully!<br>You can close this tab now.";
}).catch(err => {
// Unexpected the unexpectable
console.log(err);
status.innerHTML = "Something went wrong, check console for details";
});
2021-07-24 13:36:06 +02:00
})();
</script>
</body>
</html>