Done!
This commit is contained in:
parent
f95acf0deb
commit
550e7d1a7e
2 changed files with 9 additions and 4 deletions
|
@ -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;
|
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) {
|
export async function GainTokens(PKCEcodeName, NonceName, AccessToken, RefreshToken) {
|
||||||
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) {
|
// 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 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 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
|
||||||
let Auth = await AuthRequest("https://bsky.social/oauth/token", PKCE, code, DPoP);
|
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;";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ function CheckLogin() {
|
||||||
BlueskyLogoutButton.setAttribute("style", "");
|
BlueskyLogoutButton.setAttribute("style", "");
|
||||||
} else {
|
} else {
|
||||||
// Auto log in
|
// Auto log in
|
||||||
BlueskyAPI.GainTokens(BlueskyPKCEverifer, BlueskyNonce);
|
BlueskyAPI.GainTokens(BlueskyPKCEverifer, BlueskyNonce, BlueskyAccessToken, BlueskyRefreshToken);
|
||||||
}
|
}
|
||||||
// Check for a bluesky token.
|
// Check for a bluesky token.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue