remaining bug fixes. Sorry
This commit is contained in:
parent
9cc7038273
commit
dc1bcf5f6a
2 changed files with 38 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
export const Scopes = "read write follow push";
|
||||
let Origin = location.href;
|
||||
let Origin = document.location.href;
|
||||
|
||||
// Gets the public timeline.
|
||||
export async function GetPublicTimeline(Local = false, Remote = false, Website) {
|
||||
|
@ -74,12 +74,11 @@ export async function HandleAuthentication(Website, CookieClientID, CookieClient
|
|||
} else {
|
||||
Website = "https://" + Website;
|
||||
}
|
||||
console.log(Website);
|
||||
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.
|
||||
document.cookie = CookieClientID + "=" + InstanceData.client_id + ";samesite=strict;path=/;expires=9999-01-01;";
|
||||
document.cookie = CookieClientSecret + "=" + InstanceData.client_secret + ";samesite=strict;path=/;expires=9999-01-01;";
|
||||
document.cookie = CookieClientID + "=" + InstanceData.client_id + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
||||
document.cookie = CookieClientSecret + "=" + InstanceData.client_secret + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
||||
// Now authenticate the app.
|
||||
document.location.href = Website + "/oauth/authorize?client_id=" + InstanceData.client_id + "&redirect_uri=" + Origin + "&response_type=code&scope=" + Scopes;
|
||||
}
|
||||
|
@ -87,7 +86,7 @@ export async function HandleAuthentication(Website, CookieClientID, CookieClient
|
|||
// This specific functino goes after HandleAuthentication for when login happens.
|
||||
export async function GainToken(Website, CookieClientID, CookieClientSecret, CookieAccessToken, CookieTokenType) {
|
||||
// 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("=") > 1) {
|
||||
if (document.location.href.split("code=").length > 1 && document.cookie.split("; ").find((row) => row.startsWith(CookieClientID + "="))?.split("=").length > 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];
|
||||
|
@ -95,7 +94,7 @@ export async function GainToken(Website, CookieClientID, CookieClientSecret, Coo
|
|||
let AuthenticationToken = await fetch(Website + "/oauth/token?client_id=" + ClientID + "&client_secret=" + ClientSecret + "&redirect_uri=" + Origin + "&grant_type=authorization_code&code=" + code, {method: "POST"})
|
||||
.then((response) => response.json());
|
||||
// Cookify These
|
||||
document.cookie = CookieAccessToken + "=" + AuthenticationToken.access_token + ";samesite=strict;path=/;expires=9999-01-01;";
|
||||
document.cookie = CookieTokenType + "=" + AuthenticationToken.token_type + ";samesite=strict;path=/;expires=9999-01-01;";
|
||||
document.cookie = CookieAccessToken + "=" + AuthenticationToken.access_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
||||
document.cookie = CookieTokenType + "=" + AuthenticationToken.token_type + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
|
||||
}
|
||||
}
|
||||
|
|
54
JS/mail.js
54
JS/mail.js
|
@ -14,7 +14,7 @@ let MastodonWebsite = "https://wetdry.world";
|
|||
let MastodonClientID = "mastodon_client_id";
|
||||
let MastodonClientSecret = "mastodon_client_secret";
|
||||
let MastodonAccessToken = "mastodon_access_token";
|
||||
let MastodonTokenType = "mastodon_access_token";
|
||||
let MastodonTokenType = "mastodon_token_type";
|
||||
|
||||
// Bluesky (TODO: use these variables).
|
||||
let BlueskyApp = "https://bsky.app";
|
||||
|
@ -30,24 +30,38 @@ MastodonLoginButton.onclick = (event) => {
|
|||
}
|
||||
|
||||
MastodonLogoutButton.onclick = (event) => {
|
||||
document.cookie = MastodonAccessToken + "=nothing;" + ";samesite=strict;path=/;expires=0000-01-01;";
|
||||
document.cookie = MastodonTokenType + "=nothing;" + ";samesite=strict;path=/;expires=0000-01-01;";
|
||||
console.log("Cleared the access token.");
|
||||
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 token.
|
||||
if (document.cookie.split("; ").find((row) => row.startsWith(MastodonAccessToken + "="))?.split("=").length > 1) {
|
||||
// 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
|
||||
LoginButton.remove();
|
||||
LogoutButton.setAttribute("style", "");
|
||||
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 = MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
let Favorites = await MastodonAPI.GetFavorites(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
|
||||
let FavoritesArea = document.getElementsByClassName("Favorites")[0];
|
||||
// Populate the favorites area.
|
||||
|
@ -58,7 +72,7 @@ async function PopulateFavorites() {
|
|||
}
|
||||
|
||||
async function PopulateBookmarks() {
|
||||
let Bookmarks = MastodonAPI.GetBookmarks(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
let Bookmarks = await MastodonAPI.GetBookmarks(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
|
||||
let BookmarksArea = document.getElementsByClassName("Bookmarks")[0];
|
||||
// Populate the Bookmarks area.
|
||||
|
@ -69,7 +83,7 @@ async function PopulateBookmarks() {
|
|||
}
|
||||
|
||||
async function PopulateNotifications() {
|
||||
let Notifications = MastodonAPI.GetNotifications(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
let Notifications = await MastodonAPI.GetNotifications(MastodonWebsite, MastodonAccessToken, MastodonTokenType);
|
||||
|
||||
let NotificationsArea = document.getElementsByClassName("Notifications")[0];
|
||||
// Populate the Conversations area.
|
||||
|
@ -79,13 +93,12 @@ async function PopulateNotifications() {
|
|||
}
|
||||
}
|
||||
|
||||
await MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
|
||||
|
||||
// Runs on website start.
|
||||
// Remove traces of "login".
|
||||
CheckLogin();
|
||||
|
||||
// So far: login. TODO: Change this later.
|
||||
MastodonAPI.GainToken(MastodonWebsite, MastodonClientID, MastodonClientSecret, MastodonAccessToken, MastodonTokenType);
|
||||
|
||||
// Populate the areas.
|
||||
PopulateFavorites();
|
||||
PopulateBookmarks();
|
||||
|
@ -99,8 +112,6 @@ function getRandomArbitrary(min, max) {
|
|||
|
||||
// The next section is dedicated to testing.
|
||||
// WARNING: I don't know what I am doing.
|
||||
BlueskyAPI.ClientDPoP();
|
||||
BlueskyAPI.AssertionJWT("Nothing");
|
||||
|
||||
async function BlueskyTestingAuthorization() {
|
||||
// Declare Variables
|
||||
|
@ -110,15 +121,14 @@ async function BlueskyTestingAuthorization() {
|
|||
let State = generateToken(64);
|
||||
|
||||
let PKCEverifier = await BlueskyAPI.CreatePKCECodeVerifier();
|
||||
let PKCEchallenge = await BlueskyAPI.CreatePKCECodeChallenge(TestingVerifier);
|
||||
|
||||
let PAR = BlueskyAPI.PARrequest(WellKnown.pushed_authorization_request_endpoint, State, PKCEchallenge);
|
||||
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;
|
||||
}
|
||||
|
||||
// BlueskyTestingAuthorization();
|
||||
|
||||
// Stolen from Search
|
||||
// TODO: implement my own function.
|
||||
function generateToken(length) {
|
||||
|
|
Loading…
Add table
Reference in a new issue