diff --git a/JS/BlueskyAPI.js b/JS/BlueskyAPI.js index 57f92d1..96457b0 100644 --- a/JS/BlueskyAPI.js +++ b/JS/BlueskyAPI.js @@ -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;"; } } diff --git a/JS/setting.js b/JS/setting.js index 6a43cd1..57d122b 100644 --- a/JS/setting.js +++ b/JS/setting.js @@ -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. }