From df37d0d9537720a3b8bd3ecba3a63c1f5c03c190 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Mon, 28 Apr 2025 17:39:50 -0700 Subject: [PATCH] moving things to the proper area; final bug fixes for mastodon --- HTML/mail.html | 11 +----- HTML/setting.html | 9 ++++- JS/MastodonAPI.js | 1 + JS/mail.js | 75 +----------------------------------- JS/setting.js | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 83 deletions(-) diff --git a/HTML/mail.html b/HTML/mail.html index 7f38b5f..90d1d5f 100644 --- a/HTML/mail.html +++ b/HTML/mail.html @@ -7,8 +7,7 @@ - + @@ -17,13 +16,7 @@

Mail

- - - - - - -

Back

+

OK

diff --git a/HTML/setting.html b/HTML/setting.html index ad0cd52..bb205b8 100644 --- a/HTML/setting.html +++ b/HTML/setting.html @@ -6,15 +6,22 @@ + +

Setting

-

Just go back. It ain't ready yet...

Toggle Local

Toggle Remote

+

Login to Mastodon

+ + +

Login to Bluesky

+ +

OK

diff --git a/JS/MastodonAPI.js b/JS/MastodonAPI.js index 9355bfb..62a0920 100644 --- a/JS/MastodonAPI.js +++ b/JS/MastodonAPI.js @@ -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. diff --git a/JS/mail.js b/JS/mail.js index c81f9a1..e038497 100644 --- a/JS/mail.js +++ b/JS/mail.js @@ -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; -} diff --git a/JS/setting.js b/JS/setting.js index e23c534..ac2b7e2 100644 --- a/JS/setting.js +++ b/JS/setting.js @@ -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; +}