Created
April 3, 2023 11:54
-
-
Save blubbll/9bd6a2996bde381b359f827fd4d253dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const //imports | |
fs = require("fs"), | |
totp = require("totp-generator"), | |
fetch = require("node-fetch"); | |
const api = "https://vrchat.com/api/1"; | |
const ua = "bap [email protected]"; | |
const cookiePath = "auth.cookie"; | |
const app = async (_) => { | |
let authCookie = fs.existsSync(cookiePath) | |
? fs.readFileSync(cookiePath, "utf-8") | |
: void 0; | |
if (authCookie) { | |
console.log("Trying to login with stored cookie...") | |
const loginResult = await fetch(api + "/auth/user", { | |
headers: { | |
accept: "*/*", | |
Cookie: authCookie, | |
"user-agent": ua, | |
"content-type": "application/json", | |
}, | |
referrer: "https://vrchat.com/home/twofactorauth", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: null, | |
method: "GET", | |
mode: "cors", | |
credentials: "include", | |
}); | |
if (loginResult.status === 200) { | |
var user = await loginResult.json(); | |
console.log("logged in as", `${user.username}(${user.displayName})`); | |
// fs.writeFileSync(cookiePath, authCookie); | |
} else { | |
console.log("login failed", loginResult) | |
fs.unlinkSync(cookiePath) | |
} | |
} else { | |
const loginRes = await fetch(api + "/auth/user", { | |
headers: { | |
"user-agent": ua, | |
authorization: | |
"Basic " + | |
Buffer.from( | |
`${process.env.VRC_USERNAME}:${process.env.VRC_PASSWORD}` | |
).toString("base64"), | |
}, | |
accept: "*/*", | |
"user-agent": ua, | |
"content-type": "application/json", | |
method: "GET", | |
mode: "cors", | |
credentials: "include", | |
}); | |
const authCookie = loginRes.headers.get("set-cookie"); | |
const token = totp(process.env.VRC_2FA_SECRET); | |
const verify2fa = await fetch(api + "/auth/twofactorauth/totp/verify", { | |
headers: { | |
accept: "*/*", | |
"user-agent": ua, | |
"content-type": "application/json", | |
Cookie: authCookie, | |
}, | |
referrer: "https://vrchat.com/home/twofactorauth", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: JSON.stringify({ code: token }), | |
method: "POST", | |
mode: "cors", | |
credentials: "include", | |
}); | |
if (verify2fa.status === 200) { | |
console.log(token); | |
const loginResult = await fetch(api + "/auth/user", { | |
headers: { | |
accept: "*/*", | |
Cookie: authCookie, | |
"user-agent": ua, | |
"content-type": "application/json", | |
}, | |
referrer: "https://vrchat.com/home/twofactorauth", | |
referrerPolicy: "strict-origin-when-cross-origin", | |
body: null, | |
method: "GET", | |
mode: "cors", | |
credentials: "include", | |
}); | |
if (loginResult.status === 200) { | |
console.log("logged in as", await loginResult.json()); | |
fs.writeFileSync(cookiePath, authCookie); | |
} else console.log(loginResult); | |
// fs.readFileSync | |
} else console.log(verify2fa); | |
} | |
}; | |
app(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment