This commit is contained in:
CatAClock 2025-04-29 15:05:09 -07:00
parent f95acf0deb
commit 550e7d1a7e
2 changed files with 9 additions and 4 deletions

View file

@ -128,13 +128,18 @@ 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;
}
export async function GainTokens(PKCEcodeName, NonceName) {
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) {
export async function GainTokens(PKCEcodeName, NonceName, AccessToken, RefreshToken) {
// 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.location.href.split("code=").length > 1) && document.cookie.split("; ").find((row) => row.startsWith(AccessToken + "="))?.split("=").length == 1) {
// Create varaibles, be aware of waits because of internet.
let DPoP = await ClientDPoP("POST", "https://bsky.social/oauth/token", document.cookie.split("; ").find((row) => row.startsWith(NonceName + "="))?.split("=")[1]);
let PKCE = document.cookie.split("; ").find((row) => row.startsWith(PKCEcodeName + "="))?.split("=")[1];
let code = document.location.href.split("code=")[1];
// Authentication
let Auth = await AuthRequest("https://bsky.social/oauth/token", PKCE, code, DPoP);
console.log(Auth);
// Save the tokens and be done
document.cookie = AccessToken + "=" + Auth.access_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
document.cookie = RefreshToken + "=" + Auth.refresh_token + ";samesite=strict;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT;";
}
}

View file

@ -101,7 +101,7 @@ function CheckLogin() {
BlueskyLogoutButton.setAttribute("style", "");
} else {
// Auto log in
BlueskyAPI.GainTokens(BlueskyPKCEverifer, BlueskyNonce);
BlueskyAPI.GainTokens(BlueskyPKCEverifer, BlueskyNonce, BlueskyAccessToken, BlueskyRefreshToken);
}
// Check for a bluesky token.
}