Last active
November 13, 2022 19:28
-
-
Save janispritzkau/e09b65cba0a326914c94348aa9ffb881 to your computer and use it in GitHub Desktop.
Minecraft OAuth authentication using Puppeteer
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
#!/usr/bin/env -S deno run -A | |
// you might need to specify a different chrome executable because of a bug | |
// https://github.com/lucacasonato/deno-puppeteer/issues/65 | |
// PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable (on my linux system) | |
import { OAuthClient } from "https://deno.land/x/minecraft_lib@0.0.8/auth/mod.ts"; | |
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts"; | |
const oauthClient = new OAuthClient({ | |
tokenEndpoint: "https://login.live.com/oauth20_token.srf", | |
authorizationEndpoint: "https://login.live.com/oauth20_authorize.srf", | |
deviceAuthorizationEndpoint: "https://login.live.com/oauth20_connect.srf", | |
redirectUri: "https://login.live.com/oauth20_desktop.srf", | |
clientId: "00000000402b5328", | |
scope: "XboxLive.signin offline_access", | |
}); | |
const url = oauthClient.buildAuthorizationUri(); | |
const browser = await puppeteer.launch({ | |
headless: false, | |
defaultViewport: null, | |
ignoreDefaultArgs: [ | |
"--enable-automation", | |
"--enable-blink-features=IdleDetection", | |
], | |
args: [`--app=${url}`, "--window-size=1200,800"], | |
}); | |
const [page] = await browser.pages(); | |
let code: string; | |
while (true) { | |
await page.waitForNavigation({ timeout: 600000 }); | |
const response = oauthClient.parseAuthorizationResponse(page.url()); | |
if (response) { | |
code = response.code; | |
await browser.close(); | |
break; | |
} | |
} | |
const token = await oauthClient.requestAccessToken(code); | |
console.log(JSON.stringify(token)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment