hmm... the API isn't working?
This commit is contained in:
parent
8052582b5e
commit
abc59af2a3
6 changed files with 168 additions and 121 deletions
|
@ -1,6 +1,8 @@
|
||||||
export async function GetBlueskyDID(PDS, Handle, NonceName, AccessToken) {
|
import * as Cookie from "./Cookies.js";
|
||||||
let DPoP = ClientDPoPPDS("GET", PDS + "/xrpc/com.atproto.identity.resolveDid", document.cookie.split("; ").find((row) => row.startsWith(NonceName + "="))?.split("="), AccessToken);
|
|
||||||
let request = fetch(PDS + "/xrpc/com.atproto.identity.resolveDid?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + AccessToken, "DPoP": DPoP})
|
export async function GetBlueskyDID(PDS, Handle) {
|
||||||
|
let DPoP = ClientDPoPPDS("GET", PDS + "/xrpc/com.atproto.identity.resolveDid");
|
||||||
|
let request = fetch(PDS + "/xrpc/com.atproto.identity.resolveDid?handle=" + Handle, { method: "GET", headers: {"Authorization": "DPoP " + Cookie.BlueskyAccessTokenCookie, "DPoP": DPoP}})
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -42,17 +44,17 @@ export async function CreatePKCECodeChallenge(CodeVerifier) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component 3/4
|
// Component 3/4
|
||||||
export async function PARrequest(PAREndpoint, State, ChallengeCode) {
|
export async function PARrequest(PAREndpoint, State) {
|
||||||
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: ChallengeCode, state: State, login_hint: "crowdedgames.group" }), headers: {"Content-Type": "application/x-www-form-urlencoded"}});
|
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: Cookie.BlueskyPKCEChallengeCookie, state: State, login_hint: "crowdedgames.group" }), headers: {"Content-Type": "application/x-www-form-urlencoded"}});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function AuthRequest(TokenEndpoint, ChallengeVerifier, code, DPoP) {
|
export async function AuthRequest(TokenEndpoint, code, DPoP) {
|
||||||
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: ChallengeVerifier}), headers: { "DPoP": DPoP, "Content-Type": "application/x-www-form-urlencoded"}})
|
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: Cookie.BlueskyPKCEVeriferCookie}), headers: { "DPoP": DPoP, "Content-Type": "application/x-www-form-urlencoded"}})
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component 4/4
|
// Component 4/4
|
||||||
export async function ClientDPoPToken(POSTorGET, RequestURL, DPoPNonce) {
|
export async function ClientDPoPToken(POSTorGET, RequestURL) {
|
||||||
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
|
@ -71,7 +73,7 @@ export async function ClientDPoPToken(POSTorGET, RequestURL, DPoPNonce) {
|
||||||
Payload.htm = POSTorGET;
|
Payload.htm = POSTorGET;
|
||||||
Payload.htu = RequestURL;
|
Payload.htu = RequestURL;
|
||||||
Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000);
|
Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000);
|
||||||
Payload.nonce = DPoPNonce;
|
Payload.nonce = Cookie.BlueskyNonceCookie;
|
||||||
|
|
||||||
var sHeader = JSON.stringify(Header);
|
var sHeader = JSON.stringify(Header);
|
||||||
var sPayload = JSON.stringify(Payload);
|
var sPayload = JSON.stringify(Payload);
|
||||||
|
@ -87,7 +89,7 @@ export async function ClientDPoPToken(POSTorGET, RequestURL, DPoPNonce) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// So far does nothing? Don't touch :3
|
// So far does nothing? Don't touch :3
|
||||||
export async function ClientDPoPPDS(POSTorGET, RequestURL, DPoPNonce, AccessToken) {
|
export async function ClientDPoPPDS(POSTorGET, RequestURL) {
|
||||||
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
|
@ -106,8 +108,8 @@ export async function ClientDPoPPDS(POSTorGET, RequestURL, DPoPNonce, AccessToke
|
||||||
Payload.htm = POSTorGET;
|
Payload.htm = POSTorGET;
|
||||||
Payload.htu = RequestURL;
|
Payload.htu = RequestURL;
|
||||||
Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000);
|
Payload.iat = Math.floor(new Date(Date.now()).getTime() / 1000);
|
||||||
Payload.nonce = DPoPNonce;
|
Payload.nonce = Cookie.BlueskyNonceCookie;
|
||||||
Payload.ath = await CreatePKCECodeChallenge(AccessToken);
|
Payload.ath = await CreatePKCECodeChallenge(Cookie.BlueskyAccessTokenCookie);
|
||||||
|
|
||||||
var sHeader = JSON.stringify(Header);
|
var sHeader = JSON.stringify(Header);
|
||||||
var sPayload = JSON.stringify(Payload);
|
var sPayload = JSON.stringify(Payload);
|
||||||
|
@ -122,27 +124,27 @@ export async function ClientDPoPPDS(POSTorGET, RequestURL, DPoPNonce, AccessToke
|
||||||
return JWT;
|
return JWT;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function HandleAuthorization(BlueskyPKCEverifer, BlueskyPKCEchallenge, BlueskyNonce) {
|
export async function HandleAuthorization() {
|
||||||
// Declare Variables
|
// Declare Variables
|
||||||
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
let KeyPair = await crypto.subtle.generateKey({name: "ECDSA", namedCurve: "P-256"}, true, ["sign", "verify"]);
|
||||||
|
|
||||||
let WellKnown = await GetPDSWellKnown();
|
let WellKnown = await GetPDSWellKnown();
|
||||||
let PAREndpoint = WellKnown.pushed_authorization_request_endpoint;
|
|
||||||
|
|
||||||
let State = crypto.randomUUID();
|
let State = crypto.randomUUID();
|
||||||
|
|
||||||
let PKCEverifier = await CreatePKCECodeVerifier();
|
let PKCEverifier = await CreatePKCECodeVerifier();
|
||||||
let PKCEchallenge = await CreatePKCECodeChallenge(PKCEverifier);
|
let PKCEchallenge = await CreatePKCECodeChallenge(PKCEverifier);
|
||||||
|
// Save these
|
||||||
|
Cookie.InputCookie(Cookie.BlueskyPKCEVeriferName, PKCEverifier)
|
||||||
|
Cookie.InputCookie(Cookie.BlueskyPKCEChallengeName, PKCEchallenge)
|
||||||
// PAR request (beginning)
|
// PAR request (beginning)
|
||||||
let PAR = PARrequest(WellKnown.pushed_authorization_request_endpoint, State, PKCEchallenge);
|
let PAR = PARrequest(WellKnown.pushed_authorization_request_endpoint, State);
|
||||||
let body = await PAR.then((response) => response.json());
|
let body = await PAR.then((response) => response.json());
|
||||||
let nonce = await PAR.then((response) => response.headers.get("dpop-nonce"));
|
let nonce = await PAR.then((response) => response.headers.get("dpop-nonce"));
|
||||||
|
// Save nonce
|
||||||
|
Cookie.InputCookie(Cookie.BlueskyNonceName, nonce);
|
||||||
|
|
||||||
let ExportedKey1 = await crypto.subtle.exportKey("raw", KeyPair.publicKey);
|
let ExportedKey1 = await crypto.subtle.exportKey("raw", KeyPair.publicKey);
|
||||||
// Save these things.
|
|
||||||
document.cookie = BlueskyPKCEverifer + "=" + PKCEverifier + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
|
||||||
document.cookie = BlueskyPKCEchallenge + "=" + PKCEchallenge + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
|
||||||
document.cookie = BlueskyNonce + "=" + nonce + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
|
||||||
// Don't remove the keys. They are important.
|
// Don't remove the keys. They are important.
|
||||||
// if (document.cookie.split("; ").find((row) => row.startsWith(BlueskyPublicKey + "="))?.split("=").length == 1 || document.cookie.split("; ").find((row) => row.startsWith(BlueskyPrivateKey + "="))?.split("=").length == 1) {
|
// if (document.cookie.split("; ").find((row) => row.startsWith(BlueskyPublicKey + "="))?.split("=").length == 1 || document.cookie.split("; ").find((row) => row.startsWith(BlueskyPrivateKey + "="))?.split("=").length == 1) {
|
||||||
// document.cookie = BlueskyPublicKey + "=" + ExportedKey1 + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
// document.cookie = BlueskyPublicKey + "=" + ExportedKey1 + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
||||||
|
@ -151,18 +153,19 @@ export async function HandleAuthorization(BlueskyPKCEverifer, BlueskyPKCEchallen
|
||||||
document.location.href = "https://bsky.social/oauth/authorize?client_id=https://fedi.crowdedgames.group/oauth/client-metadata.json&request_uri=" + body.request_uri;
|
document.location.href = "https://bsky.social/oauth/authorize?client_id=https://fedi.crowdedgames.group/oauth/client-metadata.json&request_uri=" + body.request_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GainTokens(PKCEcodeName, NonceName, AccessToken, RefreshToken) {
|
export async function GainTokens() {
|
||||||
|
let WellKnown = await GetPDSWellKnown();
|
||||||
|
|
||||||
// Check to see if something's a miss...
|
// 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) && document.cookie.split("; ").find((row) => row.startsWith(PKCEcodeName + "="))?.split("=").length > 1 && document.cookie.split("; ").find((row) => row.startsWith(AccessToken + "="))?.split("=").length == 1) {
|
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)) {
|
||||||
// Create varaibles, be aware of waits because of internet.
|
// Create varaibles, be aware of waits because of internet.
|
||||||
let DPoP = await ClientDPoPToken("POST", "https://bsky.social/oauth/token", document.cookie.split("; ").find((row) => row.startsWith(NonceName + "="))?.split("=")[1]);
|
let DPoP = await ClientDPoPToken("POST", WellKnown.token_endpoint);
|
||||||
let PKCE = document.cookie.split("; ").find((row) => row.startsWith(PKCEcodeName + "="))?.split("=")[1];
|
|
||||||
let code = document.location.href.split("code=")[1];
|
let code = document.location.href.split("code=")[1];
|
||||||
// Authentication
|
// Authentication
|
||||||
let Auth = await AuthRequest("https://bsky.social/oauth/token", PKCE, code, DPoP);
|
let Auth = await AuthRequest(WellKnown.token_endpoint, code, DPoP);
|
||||||
// Save the tokens and be done
|
// Save the tokens and be done
|
||||||
document.cookie = AccessToken + "=" + Auth.access_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.BlueskyAccessTokenName, Auth.access_token);
|
||||||
document.cookie = RefreshToken + "=" + Auth.refresh_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.BlueskyRefreshTokenName, Auth.refresh_token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
81
JS/Cookies.js
Normal file
81
JS/Cookies.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
// STRINGS TODO: make sure to seperate stuff that a user will want to input. Ex: MastodonWebsiteName, BlueskyPDS, etc.
|
||||||
|
// Mastodon
|
||||||
|
export const MastodonWebsiteName = "https://wetdry.world";
|
||||||
|
export const MastodonClientIDName = "mastodon_client_id";
|
||||||
|
export const MastodonClientSecretName = "mastodon_client_secret";
|
||||||
|
export const MastodonAccessTokenName = "mastodon_access_token";
|
||||||
|
export const MastodonTokenTypeName = "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 BlueskyNonceName = "bluesky_nonce";
|
||||||
|
export const BlueskyAccessTokenName = "bluesky_access_token";
|
||||||
|
export const BlueskyRefreshTokenName = "bluesky_refresh_token";
|
||||||
|
|
||||||
|
// Tumblr
|
||||||
|
export const TumblrWebsiteName = "https://www.tumblr.com";
|
||||||
|
|
||||||
|
// COOKIES TODO: person inputted stuff (like MastodonWebsiteName) should be implemented.
|
||||||
|
// Mastodon
|
||||||
|
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 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 = "") {
|
||||||
|
// Check if you put in nothing.
|
||||||
|
if (CookieName == 0) {
|
||||||
|
console.error("Where is the cookie name? Returning nothing...");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// Get the cookie.
|
||||||
|
let Cookie = document.cookie.split("; ").find((row) => row.startsWith(CookieName + "="))?.split("=");
|
||||||
|
// If the cookie doesn't exist...
|
||||||
|
if (Cookie == undefined || Cookie.length == 1) {
|
||||||
|
console.log("Cookie not found. Returning nothing...");
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return Cookie[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a cookie is real (as in the value isn't nonexistant).
|
||||||
|
export function IsCookieReal(Cookie = "") {
|
||||||
|
if (Cookie.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the cookie.
|
||||||
|
export function ExpireCookie(CookieName = "") {
|
||||||
|
document.cookie = CookieName + "=nothing;samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new cookie (or change it's value).
|
||||||
|
export function InputCookie(CookieName = "", Value = "") {
|
||||||
|
if (Value == 0 || CookieName == 0) {
|
||||||
|
console.error("You forgot to put in a value. Stopping...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.cookie = CookieName + "=" + Value + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;"
|
||||||
|
return;
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
import * as Cookie from "./Cookies.js";
|
||||||
|
|
||||||
export const Scopes = "read write follow push";
|
export const Scopes = "read write follow push";
|
||||||
|
|
||||||
// Gets the public timeline.
|
// Gets the public timeline.
|
||||||
|
@ -22,49 +24,43 @@ export async function GetPublicTimeline(Local = false, Remote = false, Website)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the favorites of a user that you have access to.
|
// Gets the favorites of a user that you have access to.
|
||||||
export async function GetFavorites(Website, MastodonAccessToken, MastodonTokenType) {
|
export async function GetFavorites(Website) {
|
||||||
let Favorites;
|
let Favorites;
|
||||||
// Check for a token.
|
// Check for a token.
|
||||||
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
|
if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) {
|
||||||
// Get the varaibles that are stored in cookies.
|
// Get the varaibles that are stored in cookies.
|
||||||
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
|
Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}})
|
||||||
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
|
|
||||||
Favorites = await fetch(Website + "/api/v1/favourites", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
|
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
}
|
}
|
||||||
return Favorites;
|
return Favorites;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the bookmarks of a user that you have access to.
|
// Gets the bookmarks of a user that you have access to.
|
||||||
export async function GetBookmarks(Website, MastodonAccessToken, MastodonTokenType) {
|
export async function GetBookmarks(Website) {
|
||||||
let Bookmarks;
|
let Bookmarks;
|
||||||
// Check for a token.
|
// Check for a token.
|
||||||
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
|
if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) {
|
||||||
// Get the varaibles that are stored in cookies.
|
// Get the varaibles that are stored in cookies.
|
||||||
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
|
Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}})
|
||||||
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
|
|
||||||
Bookmarks = await fetch(Website + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
|
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
}
|
}
|
||||||
return Bookmarks;
|
return Bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the notifications of a user that you have access to.
|
// Gets the notifications of a user that you have access to.
|
||||||
export async function GetNotifications(Website, MastodonAccessToken, MastodonTokenType) {
|
export async function GetNotifications(Website) {
|
||||||
let Notifications;
|
let Notifications;
|
||||||
// Check for a token.
|
// Check for a token.
|
||||||
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
|
if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) {
|
||||||
// Get the varaibles that are stored in cookies.
|
// Get the varaibles that are stored in cookies and then input it.
|
||||||
let AccessToken = document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=")[1];
|
Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": Cookie.MastodonTokenTypeCookie + " " + Cookie.MastodonAccessTokenCookie}})
|
||||||
let TokenType = document.cookie.split("; ").find((row) => row.startsWith(MastodonTokenType + "="))?.split("=")[1];
|
|
||||||
Notifications = await fetch(Website + "/api/v1/notifications", {method: "GET", headers: {"Authorization": TokenType + " " + AccessToken}})
|
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
}
|
}
|
||||||
return Notifications;
|
return Notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first step to using the app.
|
// The first step to using the app.
|
||||||
export async function HandleAuthentication(Website, CookieClientID, CookieClientSecret) {
|
export async function HandleAuthentication(Website) {
|
||||||
// See if the user is smart enough to put https.
|
// See if the user is smart enough to put https.
|
||||||
let InstanceData = "";
|
let InstanceData = "";
|
||||||
// Quickly check to see if it has something before :// so it doesn't screw the link.
|
// Quickly check to see if it has something before :// so it doesn't screw the link.
|
||||||
|
@ -77,24 +73,22 @@ export async function HandleAuthentication(Website, CookieClientID, CookieClient
|
||||||
InstanceData = await fetch(Website + "/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + document.location.href + "&scopes=" + Scopes, {method: "POST"})
|
InstanceData = await fetch(Website + "/api/v1/apps?client_name=Channel Viewer&redirect_uris=" + document.location.href + "&scopes=" + Scopes, {method: "POST"})
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
// Save the client stuff as cookies.
|
// Save the client stuff as cookies.
|
||||||
document.cookie = CookieClientID + "=" + InstanceData.client_id + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.MastodonClientIDName, InstanceData.client_id);
|
||||||
document.cookie = CookieClientSecret + "=" + InstanceData.client_secret + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.MastodonClientSecretName, InstanceData.client_secret);
|
||||||
// Now authenticate the app.
|
// 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;
|
document.location.href = Website + "/oauth/authorize?client_id=" + InstanceData.client_id + "&redirect_uri=" + document.location.href + "&response_type=code&scope=" + Scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This specific functino goes after HandleAuthentication for when login happens.
|
// This specific functino goes after HandleAuthentication for when login happens.
|
||||||
export async function GainToken(Website, CookieClientID, CookieClientSecret, CookieAccessToken, CookieTokenType) {
|
export async function GainToken(Website) {
|
||||||
// check if you both have a code and have a current authentication.
|
// check if you both have a code and have a current authentication.
|
||||||
if (document.location.href.split("code=").length > 1 && document.cookie.split("; ").find((row) => row.startsWith(CookieClientID + "="))?.split("=").length > 1) {
|
if (document.location.href.split("code=").length > 1 && Cookie.IsCookieReal(Cookie.MastodonClientIDCookie)) {
|
||||||
let code = document.location.href.split("code=")[1];
|
let code = document.location.href.split("code=")[1];
|
||||||
let ClientID = document.cookie.split("; ").find((row) => row.startsWith(CookieClientID + "="))?.split("=")[1];
|
|
||||||
let ClientSecret = document.cookie.split("; ").find((row) => row.startsWith(CookieClientSecret + "="))?.split("=")[1];
|
|
||||||
|
|
||||||
let AuthenticationToken = await fetch(Website + "/oauth/token?client_id=" + ClientID + "&client_secret=" + ClientSecret + "&redirect_uri=" + document.location.href + "&grant_type=authorization_code&code=" + code, {method: "POST"})
|
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"})
|
||||||
.then((response) => response.json());
|
.then((response) => response.json());
|
||||||
// Cookify These
|
// Cookify These
|
||||||
document.cookie = CookieAccessToken + "=" + AuthenticationToken.access_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.MastodonAccessTokenName, AuthenticationToken.access_token);
|
||||||
document.cookie = CookieTokenType + "=" + AuthenticationToken.token_type + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
Cookie.InputCookie(Cookie.MastodonTokenTypeName, AuthenticationToken.token_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
JS/index.js
16
JS/index.js
|
@ -1,4 +1,7 @@
|
||||||
import * as MastodonAPI from "./MastodonAPI.js";
|
import * as MastodonAPI from "./MastodonAPI.js";
|
||||||
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
||||||
|
import * as TumblrAPI from "./TumblrAPI.js";
|
||||||
|
import * as Cookie from "./Cookies.js";
|
||||||
|
|
||||||
// GLOBAL VARS
|
// GLOBAL VARS
|
||||||
// fuck you. I see why website developers use divs so fucking often.
|
// fuck you. I see why website developers use divs so fucking often.
|
||||||
|
@ -18,9 +21,6 @@ const ButtonSound = new Audio("Audio/button-305770.mp3");
|
||||||
const WarningClick = new Audio("Audio/button-pressed-38129.mp3");
|
const WarningClick = new Audio("Audio/button-pressed-38129.mp3");
|
||||||
const BackgroundMusic = new Audio("Audio/soft-piano-music-312509.mp3");
|
const BackgroundMusic = new Audio("Audio/soft-piano-music-312509.mp3");
|
||||||
|
|
||||||
// Websites
|
|
||||||
let MastodonWebsite = "https://wetdry.world";
|
|
||||||
|
|
||||||
// Update a timer
|
// Update a timer
|
||||||
function UpdateTime() {
|
function UpdateTime() {
|
||||||
let TimeNow = new Date();
|
let TimeNow = new Date();
|
||||||
|
@ -104,12 +104,12 @@ ArrowsButton[0].onclick = (event) => {
|
||||||
// MastodonAPI integration
|
// MastodonAPI integration
|
||||||
async function PosterContainerUpdate() {
|
async function PosterContainerUpdate() {
|
||||||
// Cookies for the public timelines
|
// Cookies for the public timelines
|
||||||
let LocalCookie = document.cookie.split("; ").find((row) => row.startsWith("Local="))?.split("=")[1];
|
let LocalCookie = Cookie.GetCookie("Local");
|
||||||
var LocalTrue = (LocalCookie === 'true');
|
var LocalTrue = (LocalCookie === "true");
|
||||||
let RemoteCookie = document.cookie.split("; ").find((row) => row.startsWith("Remote="))?.split("=")[1];
|
let RemoteCookie = Cookie.GetCookie("Remote");
|
||||||
var RemoteTrue = (RemoteCookie === 'true');
|
var RemoteTrue = (RemoteCookie === "true");
|
||||||
|
|
||||||
let Timeline = await MastodonAPI.GetPublicTimeline(LocalTrue, RemoteTrue, MastodonWebsite);
|
let Timeline = await MastodonAPI.GetPublicTimeline(LocalTrue, RemoteTrue, Cookie.MastodonWebsiteName);
|
||||||
let Content = [];
|
let Content = [];
|
||||||
let Users = [];
|
let Users = [];
|
||||||
for (let i in Timeline) {
|
for (let i in Timeline) {
|
||||||
|
|
23
JS/mail.js
23
JS/mail.js
|
@ -1,26 +1,11 @@
|
||||||
import * as MastodonAPI from "./MastodonAPI.js";
|
import * as MastodonAPI from "./MastodonAPI.js";
|
||||||
import * as BlueskyAPI from "./BlueskyAPI.js";
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
||||||
import * as TumblrAPI from "./TumblrAPI.js";
|
import * as TumblrAPI from "./TumblrAPI.js";
|
||||||
|
import * as Cookie from "./Cookies.js";
|
||||||
// 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 BlueskyPublicKey = "bluesky_public_key";
|
|
||||||
let BlueskyNonce = "bluesky_nonce";
|
|
||||||
|
|
||||||
// Below is the thing it populates if you login.
|
// Below is the thing it populates if you login.
|
||||||
async function PopulateFavorites() {
|
async function PopulateFavorites() {
|
||||||
let Favorites = await MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
let Favorites = await MastodonAPI.GetFavorites(Cookie.MastodonWebsiteName);
|
||||||
|
|
||||||
let FavoritesArea = document.getElementsByClassName("Favorites")[0];
|
let FavoritesArea = document.getElementsByClassName("Favorites")[0];
|
||||||
// Populate the favorites area.
|
// Populate the favorites area.
|
||||||
|
@ -31,7 +16,7 @@ async function PopulateFavorites() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function PopulateBookmarks() {
|
async function PopulateBookmarks() {
|
||||||
let Bookmarks = await MastodonAPI.GetBookmarks(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
let Bookmarks = await MastodonAPI.GetBookmarks(Cookie.MastodonWebsiteName);
|
||||||
|
|
||||||
let BookmarksArea = document.getElementsByClassName("Bookmarks")[0];
|
let BookmarksArea = document.getElementsByClassName("Bookmarks")[0];
|
||||||
// Populate the Bookmarks area.
|
// Populate the Bookmarks area.
|
||||||
|
@ -42,7 +27,7 @@ async function PopulateBookmarks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function PopulateNotifications() {
|
async function PopulateNotifications() {
|
||||||
let Notifications = await MastodonAPI.GetNotifications(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
let Notifications = await MastodonAPI.GetNotifications(Cookie.MastodonWebsiteName);
|
||||||
|
|
||||||
let NotificationsArea = document.getElementsByClassName("Notifications")[0];
|
let NotificationsArea = document.getElementsByClassName("Notifications")[0];
|
||||||
// Populate the Conversations area.
|
// Populate the Conversations area.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as MastodonAPI from "./MastodonAPI.js";
|
import * as MastodonAPI from "./MastodonAPI.js";
|
||||||
import * as BlueskyAPI from "./BlueskyAPI.js";
|
import * as BlueskyAPI from "./BlueskyAPI.js";
|
||||||
import * as TumblrAPI from "./TumblrAPI.js";
|
import * as TumblrAPI from "./TumblrAPI.js";
|
||||||
|
import * as Cookie from "./Cookies.js";
|
||||||
|
|
||||||
// Settings buttons
|
// Settings buttons
|
||||||
let LocalButton = document.getElementsByClassName("Local")[0];
|
let LocalButton = document.getElementsByClassName("Local")[0];
|
||||||
|
@ -13,96 +14,79 @@ let BlueskyLoginButton = document.getElementsByClassName("Login Bluesky")[0];
|
||||||
let BlueskyWebInput = document.getElementsByClassName("WebInput Bluesky")[0];
|
let BlueskyWebInput = document.getElementsByClassName("WebInput Bluesky")[0];
|
||||||
let BlueskyLogoutButton = document.getElementsByClassName("Logout 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 BlueskyPublicKey = "bluesky_public_key";
|
|
||||||
let BlueskyNonce = "bluesky_nonce";
|
|
||||||
let BlueskyAccessToken = "bluesky_access_token";
|
|
||||||
let BlueskyRefreshToken = "bluesky_refresh_token";
|
|
||||||
|
|
||||||
// Tumblr
|
|
||||||
let TumblrWebsite = "https://www.tumblr.com";
|
|
||||||
|
|
||||||
// Change weather the timelines are public or remote
|
// Change weather the timelines are public or remote
|
||||||
LocalButton.onclick = (event) => {
|
LocalButton.onclick = (event) => {
|
||||||
// Toggle the cookie
|
// Toggle the cookie
|
||||||
if (document.cookie.split(";").some((item) => item.trim().startsWith("Local="))) {
|
if (Cookie.IsCookieReal(GetCookie("Local"))) {
|
||||||
document.cookie = "Local=true;samesite=strict;path=/;expires=expires=0000-01-01;";
|
Cookie.ExpireCookie(GetCookie("Local"));
|
||||||
} else {
|
} else {
|
||||||
document.cookie = "Local=true;samesite=strict;path=/;";
|
Cookie.InputCookie("Local", "true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteButton.onclick = (event) => {
|
RemoteButton.onclick = (event) => {
|
||||||
// Toggle the cookie
|
// Toggle the cookie
|
||||||
if (document.cookie.split(";").some((item) => item.trim().startsWith("Remote="))) {
|
if (Cookie.IsCookieReal(GetCookie("Remote"))) {
|
||||||
document.cookie = "Remote=true;samesite=strict;path=/;expires=expires=0000-01-01;";
|
Cookie.ExpireCookie(GetCookie("Remote"));
|
||||||
} else {
|
} else {
|
||||||
document.cookie = "Remote=true;samesite=strict;path=/;";
|
Cookie.InputCookie("Remote", "true");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mastodon buttons
|
// Mastodon buttons
|
||||||
|
// Login
|
||||||
MastodonLoginButton.onclick = (event) => {
|
MastodonLoginButton.onclick = (event) => {
|
||||||
if (MastodonWebInput != "") {
|
if (MastodonWebInput != "") {
|
||||||
MastodonAPI.HandleAuthentication(MastodonWebsite, MastodonClientID, MastodonClientSecret);
|
MastodonAPI.HandleAuthentication(Cookie.MastodonWebsiteName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logout
|
||||||
MastodonLogoutButton.onclick = (event) => {
|
MastodonLogoutButton.onclick = (event) => {
|
||||||
document.cookie = MastodonClientID + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.MastodonClientIDName);
|
||||||
document.cookie = MastodonClientSecret + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.MastodonClientSecretName);
|
||||||
document.cookie = MastodonAccessToken + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.MastodonAccessTokenName);
|
||||||
document.cookie = MastodonTokenType + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.MastodonTokenTypeName);
|
||||||
document.location.href = document.location.href;
|
document.location.href = document.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bluesky Buttons
|
// Bluesky Buttons
|
||||||
|
// Login
|
||||||
BlueskyLoginButton.onclick = (event) => {
|
BlueskyLoginButton.onclick = (event) => {
|
||||||
if (BlueskyWebInput != "") {
|
if (BlueskyWebInput != "") {
|
||||||
BlueskyAPI.HandleAuthorization(BlueskyPKCEverifer, BlueskyPKCEchallenge, BlueskyNonce);
|
BlueskyAPI.HandleAuthorization();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logout
|
||||||
BlueskyLogoutButton.onclick = (event) => {
|
BlueskyLogoutButton.onclick = (event) => {
|
||||||
document.cookie = BlueskyPKCEverifer + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.BlueskyPKCEVeriferName);
|
||||||
document.cookie = BlueskyPKCEchallenge + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.BlueskyPKCEChallengeName);
|
||||||
document.cookie = BlueskyNonce + "=nothing;" + ";samesite=strict;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT;";
|
Cookie.ExpireCookie(Cookie.BlueskyNonceName);
|
||||||
document.location.href = document.location.href;
|
document.location.href = document.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if an access token is found, login.
|
// if an access token is found, login.
|
||||||
function CheckLogin() {
|
async function CheckLogin() {
|
||||||
// Check for a mastodon token.
|
// Check for a mastodon token.
|
||||||
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1 && document.location.href.split("code=").length == 1) {
|
if (Cookie.IsCookieReal(Cookie.MastodonAccessTokenCookie)) {
|
||||||
// Swap the buttons
|
// Swap the buttons
|
||||||
MastodonLoginButton.remove();
|
MastodonLoginButton.remove();
|
||||||
MastodonWebInput.remove();
|
MastodonWebInput.remove();
|
||||||
MastodonLogoutButton.setAttribute("style", "");
|
MastodonLogoutButton.setAttribute("style", "");
|
||||||
} else {
|
} else {
|
||||||
// Auto log in
|
// Auto log in
|
||||||
await MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
|
MastodonAPI.GainToken(Cookie.MastodonWebsiteName);
|
||||||
}
|
}
|
||||||
// Check for a bluesky token.
|
// Check for a bluesky token.
|
||||||
if ((document.location.href.split("state=").length == 1 && document.location.href.split("iss=").length == 1 && document.location.href.split("code=").length == 1) && document.cookie.split("; ").find((row) => row.startsWith(BlueskyAccessToken + "="))?.split("=").length > 1) {
|
if (Cookie.IsCookieReal(Cookie.BlueskyAccessTokenCookie)) {
|
||||||
// Swap the buttons
|
// Swap the buttons
|
||||||
BlueskyLoginButton.remove();
|
BlueskyLoginButton.remove();
|
||||||
BlueskyWebInput.remove();
|
BlueskyWebInput.remove();
|
||||||
BlueskyLogoutButton.setAttribute("style", "");
|
BlueskyLogoutButton.setAttribute("style", "");
|
||||||
} else {
|
} else {
|
||||||
// Auto log in
|
// Auto log in
|
||||||
await BlueskyAPI.GainTokens(BlueskyPKCEverifer, BlueskyNonce, BlueskyAccessToken, BlueskyRefreshToken);
|
BlueskyAPI.GainTokens();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,4 +95,4 @@ function CheckLogin() {
|
||||||
CheckLogin();
|
CheckLogin();
|
||||||
|
|
||||||
// TESTING!
|
// TESTING!
|
||||||
BlueskyAPI.GetBlueskyDID(BlueskyPDS, "crowdedgames.group", document.cookie.split("; ").find((row) => row.startsWith(BlueskyAccessToken + "="))?.split("=")[1]);
|
BlueskyAPI.GetBlueskyDID(Cookie.BlueskyPDSName, "crowdedgames.group", Cookie.BlueskyAccessTokenCookie);
|
||||||
|
|
Loading…
Add table
Reference in a new issue