diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index 9a3abcf..1265857 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -2,14 +2,18 @@ import * as Cookie from "./Cookies.js"; export async function GetBlueskyDID(PDS, Handle) { let DPoP = await ClientDPoPPDS("GET", PDS + "/xrpc/com.atproto.identity.resolveHandle?handle=" + Handle); - let request = fetch(PDS + "/xrpc/com.atproto.identity.resolveHandle?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}); + let request = fetch(PDS + "/xrpc/com.atproto.identity.resolveHandle?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.GetCookie(Cookie.BlueskyAccessToken), "DPoP": DPoP}}); let body = await request.then((response) => response.json()); let status = await request.then((response) => response.status); let header = await request.then((response) => response.headers.get("dpop-nonce")); if (status == 401) { - await FixNonceMismatch(header); - request = fetch(PDS + "/xrpc/com.atproto.identity.resolveHandle?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}); - body = await request.then((response) => response.json()); + if (body.message.includes("DPoP nonce mismatch")) { + await Cookie.InputCookie(Cookie.BlueskyNonce, header); + } + if (body.message.includes("claim timestamp check failed")) { + await RefreshTokens(); + } + body = await GetBlueskyDID(PDS, Handle); } return body; } @@ -25,26 +29,23 @@ export async function CreatePost(PDS, DID, Text) { "collection": "app.bsky.feed.post", "record": Json } - console.log(DID); - console.log(RequestBody.repo); let DPoP = await ClientDPoPPDS("POST", PDS + "/xrpc/com.atproto.repo.createRecord"); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}); + let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Cookie.GetCookie(Cookie.BlueskyAccessToken), "DPoP": DPoP}}); let body = await request.then((response) => response.json()); let status = await request.then((response) => response.status); let header = await request.then((response) => response.headers.get("dpop-nonce")); if (status == 401) { - await FixNonceMismatch(header); - let request = fetch(PDS + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}}); - body = await request.then((response) => response.json()); + if (body.message.includes("DPoP nonce mismatch")) { + await Cookie.InputCookie(Cookie.BlueskyNonce, header); + } + if (body.message.includes("claim timestamp check failed")) { + await RefreshTokens(); + } + body = await CreatePost(PDS, DID, Text); } return body; } -// Added after all the components: in case of nonce mismatch... -export async function FixNonceMismatch(head) { - return Cookie.InputCookie(Cookie.BlueskyNonceName, head); -} - // Component 1/4 export async function GetPDSWellKnown() { return await fetch("https://bsky.social/.well-known/oauth-authorization-server", {method: "GET"}) @@ -79,15 +80,19 @@ export async function PARrequest(PAREndpoint, State, Challenge) { return fetch(PAREndpoint, {method: "POST", body: new URLSearchParams({ response_type: "code", code_challenge_method: "S256", scope: "atproto transition:generic", client_id: "https://fedi.crowdedgames.group/oauth/client-metadata.json", redirect_uri: "https://fedi.crowdedgames.group/HTML/setting.html", code_challenge: Challenge, state: State, login_hint: "crowdedgames.group" }), headers: {"Content-Type": "application/x-www-form-urlencoded"}}); } -export async function AuthRequest(TokenEndpoint, code, DPoP, Verify) { +async function AuthRequest(TokenEndpoint, code, DPoP, Verify) { return fetch(TokenEndpoint, {method: "POST", body: new URLSearchParams({ grant_type: "authorization_code", code: code, client_id: "https://fedi.crowdedgames.group/oauth/client-metadata.json", redirect_uri: "https://fedi.crowdedgames.group/HTML/setting.html", code_verifier: Verify}), headers: { "DPoP": DPoP, "Content-Type": "application/x-www-form-urlencoded"}}) .then((response) => response.json()); } +async function ReauthRequest(TokenEndpoint, Token, DPoP) { + return fetch(TokenEndpoint, {method: "POST", body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: Token, client_id: "https://fedi.crowdedgames.group/oauth/client-metadata.json"}), headers: { "DPoP": DPoP, "Content-Type": "application/x-www-form-urlencoded"}}); +} + // Component 4/4 export async function ClientDPoPToken(POSTorGET, RequestURL) { - let PublicKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.BlueskyPublicKeyCookie), {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"]); - let PrivateKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.BlueskyPrivateKeyCookie), {name: "ECDSA", namedCurve: "P-256"}, true, ["sign"]); + let PublicKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.GetCookie(Cookie.BlueskyPublicKey)), {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"]); + let PrivateKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.GetCookie(Cookie.BlueskyPrivateKey)), {name: "ECDSA", namedCurve: "P-256"}, true, ["sign"]); // Header var Header = {typ: "dpop+jwt", alg: "ES256", jwk: @@ -105,7 +110,7 @@ export async function ClientDPoPToken(POSTorGET, RequestURL) { Payload.htm = POSTorGET; Payload.htu = RequestURL; Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000); - Payload.nonce = Cookie.BlueskyNonceCookie; + Payload.nonce = Cookie.GetCookie(Cookie.BlueskyNonce); var sHeader = JSON.stringify(Header); var sPayload = JSON.stringify(Payload); @@ -120,10 +125,9 @@ export async function ClientDPoPToken(POSTorGET, RequestURL) { return JWT; } -// So far does nothing? Don't touch :3 export async function ClientDPoPPDS(POSTorGET, RequestURL) { - let PublicKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.BlueskyPublicKeyCookie), {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"]); - let PrivateKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.BlueskyPrivateKeyCookie), {name: "ECDSA", namedCurve: "P-256"}, true, ["sign"]); + let PublicKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.GetCookie(Cookie.BlueskyPublicKey)), {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"]); + let PrivateKey = await crypto.subtle.importKey("jwk", JSON.parse(Cookie.GetCookie(Cookie.BlueskyPrivateKey)), {name: "ECDSA", namedCurve: "P-256"}, true, ["sign"]); // Header var Header = {typ: "dpop+jwt", alg: "ES256", jwk: @@ -141,8 +145,8 @@ export async function ClientDPoPPDS(POSTorGET, RequestURL) { Payload.htm = POSTorGET; Payload.htu = RequestURL; Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000); - Payload.nonce = Cookie.BlueskyNonceCookie; - Payload.ath = await CreatePKCECodeChallenge(Cookie.BlueskyAccessTokenCookie); + Payload.nonce = Cookie.GetCookie(Cookie.BlueskyNonce); + Payload.ath = await CreatePKCECodeChallenge(Cookie.GetCookie(Cookie.BlueskyAccessToken)); var sHeader = JSON.stringify(Header); var sPayload = JSON.stringify(Payload); @@ -168,20 +172,20 @@ export async function HandleAuthorization() { let PKCEverifier = await CreatePKCECodeVerifier(); let PKCEchallenge = await CreatePKCECodeChallenge(PKCEverifier); // Save these - Cookie.InputCookie(Cookie.BlueskyPKCEVeriferName, PKCEverifier); - Cookie.InputCookie(Cookie.BlueskyPKCEChallengeName, PKCEchallenge); + Cookie.InputCookie(Cookie.BlueskyPKCEVerifier, PKCEverifier); + Cookie.InputCookie(Cookie.BlueskyPKCEChallenge, PKCEchallenge); // PAR request (beginning) let PAR = PARrequest(WellKnown.pushed_authorization_request_endpoint, State, PKCEchallenge); let body = await PAR.then((response) => response.json()); let nonce = await PAR.then((response) => response.headers.get("dpop-nonce")); // Save nonce - Cookie.InputCookie(Cookie.BlueskyNonceName, nonce); + Cookie.InputCookie(Cookie.BlueskyNonce, nonce); // Export keys let ExportedKey1 = await crypto.subtle.exportKey("jwk", KeyPair.publicKey); let ExportedKey2 = await crypto.subtle.exportKey("jwk", KeyPair.privateKey); // Convert them into a good format. - Cookie.InputCookie(Cookie.BlueskyPublicKeyName, JSON.stringify(ExportedKey1)); - Cookie.InputCookie(Cookie.BlueskyPrivateKeyName, JSON.stringify(ExportedKey2)); + Cookie.InputCookie(Cookie.BlueskyPublicKey, JSON.stringify(ExportedKey1)); + Cookie.InputCookie(Cookie.BlueskyPrivateKey, JSON.stringify(ExportedKey2)); // 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=" + body.request_uri; } @@ -190,19 +194,39 @@ export async function GainTokens() { let WellKnown = await GetPDSWellKnown(); // Check to see if something's a miss... - if ((document.location.href.split("state=").length > 1 && document.location.href.split("iss=").length > 1 && document.location.href.split("code=").length > 1) && Cookie.IsCookieReal(Cookie.BlueskyPKCEVeriferCookie) && !(Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie))) { + if ((document.location.href.split("state=").length > 1 && document.location.href.split("iss=").length > 1 && document.location.href.split("code=").length > 1) && Cookie.IsCookieReal(Cookie.BlueskyPKCEVerifier) && !(Cookie.IsCookieReal(Cookie.BlueskyAccessToken))) { // Create varaibles, be aware of waits because of internet. let DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint); let code = document.location.href.split("code=")[1]; // Authentication - let cookie = await Cookie.BlueskyPKCEVeriferCookie; + let cookie = await Cookie.GetCookie(Cookie.BlueskyPKCEVerifier); let Auth = await AuthRequest(WellKnown.token_endpoint, code, DPoP, cookie); // Save the tokens and be done - Cookie.InputCookie(Cookie.BlueskyAccessTokenName, Auth.access_token); - Cookie.InputCookie(Cookie.BlueskyRefreshTokenName, Auth.refresh_token); + Cookie.InputCookie(Cookie.BlueskyAccessToken, Auth.access_token); + Cookie.InputCookie(Cookie.BlueskyRefreshToken, Auth.refresh_token); } } +// Refreshing tokens is an integral part of auth. +export async function RefreshTokens() { + let WellKnown = await GetPDSWellKnown(); + // Create varaibles, be aware of waits because of internet. + let DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint); + // Token refresh + let cookie = await Cookie.GetCookie(Cookie.BlueskyRefreshToken); + let Auth = ReauthRequest(WellKnown.token_endpoint, cookie, DPoP); + let body = await Auth.then((response) => response.json()); + let header = await Auth.then((response) => response.headers.get("dpop-nonce")); + if (body.hasOwnProperty("error_description") && body.error_description.includes("DPoP nonce mismatch")) { + await Cookie.InputCookie(Cookie.BlueskyNonce, header); + DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint); + let body = await ReauthRequest(WellKnown.token_endpoint, cookie, DPoP).then((response) => response.json()); + } + // Save the tokens and be done + Cookie.InputCookie(Cookie.BlueskyAccessToken, body.access_token); + Cookie.InputCookie(Cookie.BlueskyRefreshToken, body.refresh_token); +} + // Stolen from elsewhere. // Firefox snippet; Slightly edited. async function sha256(message) { diff --git a/JS/Cookies.js b/JS/Cookies.js index 800013c..467c5f0 100644 --- a/JS/Cookies.js +++ b/JS/Cookies.js @@ -1,45 +1,25 @@ -// STRINGS TODO: make sure to seperate stuff that a user will want to input. Ex: MastodonWebsiteName, BlueskyPDS, etc. +// STRINGS TODO: make sure to seperate stuff that a user will want to input: BlueskyAppName, BlueskyPDSName. // Mastodon -export const MastodonWebsiteName = "mastodon_website"; -export const MastodonClientIDName = "mastodon_client_id"; -export const MastodonClientSecretName = "mastodon_client_secret"; -export const MastodonAccessTokenName = "mastodon_access_token"; -export const MastodonTokenTypeName = "mastodon_token_type"; +export const MastodonWebsite = "mastodon_website"; +export const MastodonClientID = "mastodon_client_id"; +export const MastodonClientSecret = "mastodon_client_secret"; +export const MastodonAccessToken = "mastodon_access_token"; +export const MastodonTokenType = "mastodon_token_type"; // Bluesky -export const BlueskyAppName = "https://bsky.app"; -export const BlueskyPDSName = "https://bsky.social"; -export const BlueskyPKCEVeriferName = "bluesky_pkce_verifier"; -export const BlueskyPKCEChallengeName = "bluesky_pkce_challenge"; -export const BlueskyPublicKeyName = "bluesky_public_key"; -export const BlueskyPrivateKeyName = "bluesky_private_key"; -export const BlueskyNonceName = "bluesky_nonce"; -export const BlueskyAccessTokenName = "bluesky_access_token"; -export const BlueskyRefreshTokenName = "bluesky_refresh_token"; +export const BlueskyApp = "https://bsky.app"; +export const BlueskyPDS = "https://bsky.social"; +export const BlueskyPKCEVerifier = "bluesky_pkce_verifier"; +export const BlueskyPKCEChallenge = "bluesky_pkce_challenge"; +export const BlueskyPublicKey = "bluesky_public_key"; +export const BlueskyPrivateKey = "bluesky_private_key"; +export const BlueskyNonce = "bluesky_nonce"; +export const BlueskyAccessToken = "bluesky_access_token"; +export const BlueskyRefreshToken = "bluesky_refresh_token"; // Tumblr export const TumblrWebsiteName = "https://www.tumblr.com"; -// COOKIES TODO: person inputted stuff (like MastodonWebsiteName) should be implemented. -// Mastodon -export const MastodonWebsiteCookie = GetCookie(MastodonWebsiteName); -export const MastodonClientIDCookie = GetCookie(MastodonClientIDName); -export const MastodonClientSecretCookie = GetCookie(MastodonClientSecretName); -export const MastodonAccessTokenCookie = GetCookie(MastodonAccessTokenName); -export const MastodonTokenTypeCookie = GetCookie(MastodonTokenTypeName); - -// Bluesky -export const BlueskyPKCEVeriferCookie = GetCookie(BlueskyPKCEVeriferName); -export const BlueskyPKCEChallengeCookie = GetCookie(BlueskyPKCEChallengeName); -export const BlueskyPublicKeyCookie = GetCookie(BlueskyPublicKeyName); -export const BlueskyPrivateKeyCookie = GetCookie(BlueskyPrivateKeyName); -export const BlueskyNonceCookie = GetCookie(BlueskyNonceName); -export const BlueskyAccessTokenCookie = GetCookie(BlueskyAccessTokenName); -export const BlueskyRefreshTokenCookie = GetCookie(BlueskyRefreshTokenName); - -// Tumblr -// None lmao. - // FUNCTIONS // Get the cookie from cookie storage. export function GetCookie(CookieName = "") { @@ -60,7 +40,8 @@ export function GetCookie(CookieName = "") { } // Check if a cookie is real (as in the value isn't nonexistant). -export function IsCookieReal(Cookie = "") { +export function IsCookieReal(CookieName = "") { + let Cookie = GetCookie(CookieName); if (Cookie.length == 0) { return false; } diff --git a/JS/MastodonAPI.js b/JS/MastodonAPI.js index 95d20d7..91ea634 100644 --- a/JS/MastodonAPI.js +++ b/JS/MastodonAPI.js @@ -28,10 +28,10 @@ export async function GetPublicTimeline(Local = false, Remote = false, Website) export async function GetFavorites() { let Favorites; // Check for a token. - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { - let Website = Cookie.MastodonWebsiteCookie; + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { + let Website = Cookie.MastodonWebsite; // Get the varaibles that are stored in cookies. - Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) + Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": Cookie.GetCookie(Cookie.MastodonTokenType) + " " + Cookie.GetCookie(Cookie.MastodonAccessToken)}}) .then((response) => response.json()); } return Favorites; @@ -41,10 +41,10 @@ export async function GetFavorites() { export async function GetBookmarks() { let Bookmarks; // Check for a token. - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { - let Website = Cookie.MastodonWebsiteCookie; + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { + let Website = Cookie.GetCookie(Cookie.MastodonWebsite); // Get the varaibles that are stored in cookies. - Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) + Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": Cookie.GetCookie(Cookie.MastodonTokenType) + " " + Cookie.GetCookie(Cookie.MastodonAccessToken)}}) .then((response) => response.json()); } return Bookmarks; @@ -54,10 +54,10 @@ export async function GetBookmarks() { export async function GetNotifications() { let Notifications; // Check for a token. - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { - let Website = Cookie.MastodonWebsiteCookie; + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { + let Website = Cookie.GetCookie(Cookie.MastodonWebsite); // Get the varaibles that are stored in cookies and then input it. - Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) + Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": Cookie.GetCookie(Cookie.MastodonTokenType) + " " + Cookie.GetCookie(Cookie.MastodonAccessToken)}}) .then((response) => response.json()); } return Notifications; @@ -66,9 +66,9 @@ export async function GetNotifications() { // Make a status export async function CreateStatus(Text) { // Check for a token - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { let Website = Cookie.MastodonWebsiteCookie; - return await fetch(Website + "/api/v1/statuses?status=" + Text , {method: "POST", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}}) + return await fetch(Website + "/api/v1/statuses?status=" + Text , {method: "POST", headers: {"Authorization": Cookie.GetCookie(Cookie.MastodonTokenType) + " " + Cookie.GetCookie(Cookie.MastodonAccessToken)}}) .then((response) => response.json()); } } @@ -84,13 +84,13 @@ export async function HandleAuthentication(Website) { Website = "https://" + Website; } // Save the website - Cookie.InputCookie(Cookie.MastodonWebsiteName, Website); + Cookie.InputCookie(Cookie.MastodonWebsite, Website); // Registering the app. InstanceData = await fetch(Website + "/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + document.location.href + "&scopes=" + Scopes, {method: "POST"}) .then((response) => response.json()); // Save the client stuff as cookies. - Cookie.InputCookie(Cookie.MastodonClientIDName, InstanceData.client_id); - Cookie.InputCookie(Cookie.MastodonClientSecretName, InstanceData.client_secret); + Cookie.InputCookie(Cookie.MastodonClientID, InstanceData.client_id); + Cookie.InputCookie(Cookie.MastodonClientSecret, InstanceData.client_secret); // Now authenticate the app. document.location.href = Website + "/oauth/authorize?client_id=" + InstanceData.client_id + "&redirect_uri=" + document.location.href + "&response_type=code&scope=" + Scopes; } @@ -98,15 +98,15 @@ export async function HandleAuthentication(Website) { // This specific functino goes after HandleAuthentication for when login happens. export async function GainToken() { // check if you both have a code and have a current authentication. - if (document.location.href.split("code=").length > 1 && Cookie.IsCookieReal(Cookie.MastodonClientIDCookie) && !(Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie))) { + if (document.location.href.split("code=").length > 1 && Cookie.IsCookieReal(Cookie.MastodonClientID) && !(Cookie.IsCookieReal(Cookie.MastodonAccessToken))) { // Get some vars. let code = document.location.href.split("code=")[1]; - let Website = Cookie.MastodonWebsiteCookie; + let Website = Cookie.GetCookie(Cookie.MastodonWebsite); // Authenticate. - let AuthenticationToken = await fetch(Website + "/oauth/token?client_id=" + Cookie.MastodonClientIDCookie + "&client_secret=" + Cookie.MastodonClientSecretCookie + "&redirect_uri=" + document.location.href + "&grant_type=authorization_code&code=" + code, {method: "POST"}) + let AuthenticationToken = await fetch(Website + "/oauth/token?client_id=" + Cookie.GetCookie(Cookie.MastodonClientID) + "&client_secret=" + Cookie.GetCookie(Cookie.MastodonClientSecret) + "&redirect_uri=" + document.location.href + "&grant_type=authorization_code&code=" + code, {method: "POST"}) .then((response) => response.json()); // Cookify These. - Cookie.InputCookie(Cookie.MastodonAccessTokenName, AuthenticationToken.access_token); - Cookie.InputCookie(Cookie.MastodonTokenTypeName, AuthenticationToken.token_type); + Cookie.InputCookie(Cookie.MastodonAccessToken, AuthenticationToken.access_token); + Cookie.InputCookie(Cookie.MastodonTokenType, AuthenticationToken.token_type); } } diff --git a/JS/index.js b/JS/index.js index aadf229..b0047ba 100644 --- a/JS/index.js +++ b/JS/index.js @@ -109,9 +109,9 @@ async function PosterContainerUpdate() { var LocalTrue = (LocalCookie === "true"); let RemoteCookie = Cookie.GetCookie("Remote"); var RemoteTrue = (RemoteCookie === "true"); - let Website = Cookie.MastodonWebsiteCookie; + let Website = Cookie.GetCookie(Cookie.MastodonWebsite); - if (!(Cookie.IsCookieReal(Cookie.MastodonWebsiteCookie))) { + if (!(Cookie.IsCookieReal(Cookie.MastodonWebsite))) { Website = "https://wetdry.world"; } diff --git a/JS/post.js b/JS/post.js index cf772e9..00878f3 100644 --- a/JS/post.js +++ b/JS/post.js @@ -15,11 +15,11 @@ PostButton.onclick = (event) => { async function Post() { let Text = InputArea.value; // Mastodon posting. - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { MastodonAPI.CreateStatus(Text); } // Bluesky posting. - if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) { + if (Cookie.IsCookieReal(Cookie.BlueskyAccessToken)) { let DID = await BlueskyAPI.GetBlueskyDID("https://woodear.us-west.host.bsky.network", "crowdedgames.group"); BlueskyAPI.CreatePost("https://woodear.us-west.host.bsky.network", DID.did, Text); } diff --git a/JS/setting.js b/JS/setting.js index 8c1560e..581b546 100644 --- a/JS/setting.js +++ b/JS/setting.js @@ -20,7 +20,7 @@ let Origin = location.origin + "/HTML/setting.html" // Change weather the timelines are public or remote LocalButton.onclick = (event) => { // Toggle the cookie - if (Cookie.IsCookieReal(Cookie.GetCookie("Local"))) { + if (Cookie.IsCookieReal("Local")) { Cookie.ExpireCookie("Local"); } else { Cookie.InputCookie("Local", "true"); @@ -29,7 +29,7 @@ LocalButton.onclick = (event) => { RemoteButton.onclick = (event) => { // Toggle the cookie - if (Cookie.IsCookieReal(Cookie.GetCookie("Remote"))) { + if (Cookie.IsCookieReal("Romote")) { Cookie.ExpireCookie("Remote"); } else { Cookie.InputCookie("Remote", "true"); @@ -47,10 +47,10 @@ MastodonLoginButton.onclick = (event) => { // Logout MastodonLogoutButton.onclick = (event) => { - Cookie.ExpireCookie(Cookie.MastodonClientIDName); - Cookie.ExpireCookie(Cookie.MastodonClientSecretName); - Cookie.ExpireCookie(Cookie.MastodonAccessTokenName); - Cookie.ExpireCookie(Cookie.MastodonTokenTypeName); + Cookie.ExpireCookie(Cookie.MastodonClientID); + Cookie.ExpireCookie(Cookie.MastodonClientSecret); + Cookie.ExpireCookie(Cookie.MastodonAccessToken); + Cookie.ExpireCookie(Cookie.MastodonTokenType); document.location.href = Origin; } @@ -64,30 +64,30 @@ BlueskyLoginButton.onclick = (event) => { // Logout BlueskyLogoutButton.onclick = (event) => { - Cookie.ExpireCookie(Cookie.BlueskyPKCEVeriferName); - Cookie.ExpireCookie(Cookie.BlueskyPKCEChallengeName); - Cookie.ExpireCookie(Cookie.BlueskyNonceName); - Cookie.ExpireCookie(Cookie.BlueskyAccessTokenName); - Cookie.ExpireCookie(Cookie.BlueskyRefreshTokenName); - Cookie.ExpireCookie(Cookie.BlueskyPublicKeyName); - Cookie.ExpireCookie(Cookie.BlueskyPrivateKeyName); + Cookie.ExpireCookie(Cookie.BlueskyPKCEVerifier); + Cookie.ExpireCookie(Cookie.BlueskyPKCEChallenge); + Cookie.ExpireCookie(Cookie.BlueskyNonce); + Cookie.ExpireCookie(Cookie.BlueskyAccessToken); + Cookie.ExpireCookie(Cookie.BlueskyRefreshToken); + Cookie.ExpireCookie(Cookie.BlueskyPublicKey); + Cookie.ExpireCookie(Cookie.BlueskyPrivateKey); document.location.href = Origin; } // if an access token is found, login. async function CheckLogin() { // Check for a mastodon token. - if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) { + if (Cookie.IsCookieReal(Cookie.MastodonAccessToken)) { // Swap the buttons MastodonLoginButton.remove(); MastodonWebInput.remove(); MastodonLogoutButton.setAttribute("style", ""); } else { // Auto log in - await MastodonAPI.GainToken(Cookie.MastodonWebsiteName); + await MastodonAPI.GainToken(Cookie.MastodonWebsite); } // Check for a bluesky token. - if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) { + if (Cookie.IsCookieReal(Cookie.BlueskyAccessToken)) { // Swap the buttons BlueskyLoginButton.remove(); BlueskyWebInput.remove();