moving things to the proper area; final bug fixes for mastodon

This commit is contained in:
CatAClock 2025-04-28 17:39:50 -07:00
parent e6a9c04944
commit df37d0d953
5 changed files with 109 additions and 83 deletions

View file

@ -7,8 +7,7 @@
<link rel="stylesheet" href="../CSS/mail.css">
<script type="module" src="../JS/mail.js"></script>
<!-- Dependenci -->
<script language="JavaScript" type="text/javascript" src="https://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js">
</script>
<script language="JavaScript" type="text/javascript" src="https://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js"></script>
</head>
<body style="margin: 0px; text-align: center;">
@ -17,13 +16,7 @@
<section style="position: absolute; width: 100%; height: 100%" class="Notifications"></section>
<header style="position: relative; z-index: 1;">
<h1>Mail</h1>
<p class="Login Mastodon"><em>Login</em></p>
<input type="text" minlength="6" class="WebInput Mastodon" required />
<p class="Logout Mastodon" style="visibility: hidden;"><em>Logout</em></p>
<p class="Login Bluesky"><em>Login</em></p>
<input type="text" minlength="6" class="WebInput Bluesky" required />
<p class="Logout Bluesky" style="visibility: hidden;"><em>Logout</em></p>
<p onclick="history.back()"><b>Back</b></p>
<p onclick="history.back()"><b>OK</b></p>
</header>
</body>
</html>

View file

@ -6,15 +6,22 @@
<link rel="icon" href="../Icons/favicon.ico" />
<script type="module" src="../JS/setting.js"></script>
<!-- Dependenci -->
<script language="JavaScript" type="text/javascript" src="https://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js"></script>
</head>
<body style="margin: 0px; text-align: center;">
<header>
<h1>Setting</h1>
</header>
<p>Just go back. It ain't ready yet...</p>
<p class="Local">Toggle Local</p>
<p class="Remote">Toggle Remote</p>
<p class="Login Mastodon"><em>Login to Mastodon</em></p>
<input type="text" minlength="6" class="WebInput Mastodon" required />
<p class="Logout Mastodon" style="visibility: hidden;"><em>Logout of Mastodon</em></p>
<p class="Login Bluesky"><em>Login to Bluesky</em></p>
<input type="text" minlength="6" class="WebInput Bluesky" required />
<p class="Logout Bluesky" style="visibility: hidden;"><em>Logout of Mastodon</em></p>
<p onclick="history.back()"><b>OK</b></p>
</body>
</html>

View file

@ -74,6 +74,7 @@ export async function HandleAuthentication(Website, CookieClientID, CookieClient
} else {
Website = "https://" + Website;
}
// Registering the app.
InstanceData = await fetch(Website + "/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + Origin + "&scopes=" + Scopes, {method: "POST"})
.then((response) => response.json());
// Save the client stuff as cookies.

View file

@ -2,13 +2,7 @@ import * as MastodonAPI from "./MastodonAPI.js";
import * as BlueskyAPI from "./BlueskyAPI.js";
import * as TumblrAPI from "./TumblrAPI.js";
let MastodonLoginButton = document.getElementsByClassName("Login Mastodon")[0];
let MastodonWebInput = document.getElementsByClassName("WebInput Mastodon")[0];
let MastodonLogoutButton = document.getElementsByClassName("Logout Mastodon")[0];
let BlueskyLoginButton = document.getElementsByClassName("Login Bluesky")[0];
let BlueskyWebInput = document.getElementsByClassName("WebInput Bluesky")[0];
let BlueskyLogoutButton = document.getElementsByClassName("Logout Bluesky")[0];
// MAKE SURE THESE ARE SYNCED!
// Mastodon
let MastodonWebsite = "https://wetdry.world";
let MastodonClientID = "mastodon_client_id";
@ -16,7 +10,7 @@ let MastodonClientSecret = "mastodon_client_secret";
let MastodonAccessToken = "mastodon_access_token";
let MastodonTokenType = "mastodon_token_type";
// Bluesky (TODO: use these variables).
// Bluesky
let BlueskyApp = "https://bsky.app";
let BlueskyPDS = "https://bsky.social";
let BlueskyPKCEverifer = "bluesky_pkce_verifier";
@ -25,45 +19,6 @@ let BlueskyPrivateKey = "bluesky_private_key";
let BlueskyPublicKey = "bluesky_public_key";
let BlueskyNonce = "bluesky_nonce";
// Tumblr
let TumblrWebsite = "https://www.tumblr.com";
MastodonLoginButton.onclick = (event) => {
if (MastodonWebInput != "") {
MastodonAPI.HandleAuthentication(MastodonWebsite, MastodonClientID, MastodonClientSecret);
}
}
MastodonLogoutButton.onclick = (event) => {
document.cookie = MastodonClientID + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonClientSecret + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonAccessToken + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonTokenType + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.location.href = document.location.href;
}
BlueskyLoginButton.onclick = (event) => {
if (BlueskyWebInput != "") {
BlueskyTestingAuthorization();
}
}
BlueskyLogoutButton.onclick = (event) => {
// Nothing at the moment
}
// if an access token is found, login.
function CheckLogin() {
// Check for a mastodon token.
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1 && !document.location.href.split("code=").length) {
// Swap the buttons
MastodonLoginButton.remove();
MastodonWebInput.remove();
MastodonLogoutButton.setAttribute("style", "");
}
// Check for a bluesky token.
}
// Below is the thing it populates if you login.
async function PopulateFavorites() {
let Favorites = await MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
@ -98,12 +53,6 @@ async function PopulateNotifications() {
}
}
await MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
// Runs on website start.
// Remove traces of "login".
CheckLogin();
// Populate the areas.
PopulateFavorites();
PopulateBookmarks();
@ -114,23 +63,3 @@ PopulateNotifications();
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
// The next section is dedicated to testing.
// WARNING: I don't know what I am doing.
await BlueskyAPI.AssertionJWT();
async function BlueskyTestingAuthorization() {
// Declare Variables
let WellKnown = await BlueskyAPI.GetPDSWellKnown();
let PAREndpoint = WellKnown.pushed_authorization_request_endpoint;
let State = BlueskyAPI.GenerateToken(64);
let PKCEverifier = await BlueskyAPI.CreatePKCECodeVerifier();
let PKCEchallenge = await BlueskyAPI.CreatePKCECodeChallenge(PKCEverifier);
// PAR request (beginning)
let PAR = await BlueskyAPI.PARrequest(WellKnown.pushed_authorization_request_endpoint, State, PKCEchallenge);
console.log(PAR);
// Now we need to authenticate. Make sure the State stays the same throughout this whole process :]
// document.location.href = "https://bsky.social/oauth/authorize?client_id=https://fedi.crowdedgames.group/oauth/client-metadata.json&request_uri=" + PAR.request_uri;
}

View file

@ -1,6 +1,39 @@
import * as MastodonAPI from "./MastodonAPI.js";
import * as BlueskyAPI from "./BlueskyAPI.js";
import * as TumblrAPI from "./TumblrAPI.js";
// Settings buttons
let LocalButton = document.getElementsByClassName("Local")[0];
let RemoteButton = document.getElementsByClassName("Remote")[0];
let MastodonLoginButton = document.getElementsByClassName("Login Mastodon")[0];
let MastodonWebInput = document.getElementsByClassName("WebInput Mastodon")[0];
let MastodonLogoutButton = document.getElementsByClassName("Logout Mastodon")[0];
let BlueskyLoginButton = document.getElementsByClassName("Login Bluesky")[0];
let BlueskyWebInput = document.getElementsByClassName("WebInput Bluesky")[0];
let BlueskyLogoutButton = document.getElementsByClassName("Logout Bluesky")[0];
// MAKE SURE THESE ARE SYNCED!
// Mastodon
let MastodonWebsite = "https://wetdry.world";
let MastodonClientID = "mastodon_client_id";
let MastodonClientSecret = "mastodon_client_secret";
let MastodonAccessToken = "mastodon_access_token";
let MastodonTokenType = "mastodon_token_type";
// Bluesky
let BlueskyApp = "https://bsky.app";
let BlueskyPDS = "https://bsky.social";
let BlueskyPKCEverifer = "bluesky_pkce_verifier";
let BlueskyPKCEchallenge = "bluesky_pkce_challenge";
let BlueskyPrivateKey = "bluesky_private_key";
let BlueskyPublicKey = "bluesky_public_key";
let BlueskyNonce = "bluesky_nonce";
// Tumblr
let TumblrWebsite = "https://www.tumblr.com";
// Change weather the timelines are public or remote
LocalButton.onclick = (event) => {
// Toggle the cookie
if (document.cookie.split(";").some((item) => item.trim().startsWith("Local="))) {
@ -18,3 +51,66 @@ RemoteButton.onclick = (event) => {
document.cookie = "Remote=true;samesite=strict;path=/;";
}
}
// Mastodon buttons
MastodonLoginButton.onclick = (event) => {
if (MastodonWebInput != "") {
MastodonAPI.HandleAuthentication(MastodonWebsite, MastodonClientID, MastodonClientSecret);
}
}
MastodonLogoutButton.onclick = (event) => {
document.cookie = MastodonClientID + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonClientSecret + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonAccessToken + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.cookie = MastodonTokenType + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
document.location.href = document.location.href;
}
// Bluesky Buttons
BlueskyLoginButton.onclick = (event) => {
if (BlueskyWebInput != "") {
BlueskyTestingAuthorization();
}
}
BlueskyLogoutButton.onclick = (event) => {
// Nothing at the moment
}
// if an access token is found, login.
function CheckLogin() {
// Check for a mastodon token.
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1 || document.location.href.split("code=").length == 1) {
// Swap the buttons
MastodonLoginButton.remove();
MastodonWebInput.remove();
MastodonLogoutButton.setAttribute("style", "");
} else {
MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
}
// Check for a bluesky token.
}
// Runs on website start.
// Remove traces of "login".
CheckLogin();
// The next section is dedicated to testing.
// WARNING: I don't know what I am doing.
await BlueskyAPI.AssertionJWT();
async function BlueskyTestingAuthorization() {
// Declare Variables
let WellKnown = await BlueskyAPI.GetPDSWellKnown();
let PAREndpoint = WellKnown.pushed_authorization_request_endpoint;
let State = BlueskyAPI.GenerateToken(64);
let PKCEverifier = await BlueskyAPI.CreatePKCECodeVerifier();
let PKCEchallenge = await BlueskyAPI.CreatePKCECodeChallenge(PKCEverifier);
// PAR request (beginning)
let PAR = await BlueskyAPI.PARrequest(WellKnown.pushed_authorization_request_endpoint, State, PKCEchallenge);
// Now we need to authenticate. Make sure the State stays the same throughout this whole process :]
// document.location.href = "https://bsky.social/oauth/authorize?client_id=https://fedi.crowdedgames.group/oauth/client-metadata.json&request_uri=" + PAR.request_uri;
}