Add Discord OAuth2 login and refactor authentication

Implemented Discord OAuth2 authentication flow with a new Discord.cs handler and integrated it into Program.cs. Refactored authentication logic to use shared JsonSerializerOptions from LauncherConstants. Updated BashUtils with cross-platform URL opening, improved MojangAPI to use shared HttpClient, and enhanced frontend login and log handling in logged.js and login.js.
This commit is contained in:
2026-01-24 23:35:02 +01:00
parent 4ffe3b47c2
commit d2ae3122c9
7 changed files with 152 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
const buttons = document.querySelectorAll("button[frame]")
const dynmapFrame = document.querySelector("article.frame.dynmap > iframe")
const capesSelector = document.querySelector("article.capes > div.capes")
const logsContainer = document.querySelector("div.container.logs")
let viewerInstance = new skinview3d.SkinViewer({
canvas: document.getElementById("skin"),
@@ -99,7 +100,7 @@ window.initSkin = async function initSkin() {
canvas: document.getElementById("skin"),
width: container.clientWidth,
height: container.clientHeight,
skin: `https://yggdrasil.azures.fr/textures/${profile.skins.find(skin => skin.state == "ACTIVE").url}`.replace(/\/+$/, "")
skin: `https://yggdrasil.azures.fr/textures/${profile.skins.find(skin => skin.state == "ACTIVE").url.replace(/^\//, "")}`
})
const activeCape = window.profile.capes.find(s => s.state === "ACTIVE") || null
@@ -228,6 +229,18 @@ window.changeUsername = async function changeUsername(newName) {
}
}
window.gamelog = {}
window.gamelog.put = async function put(log) {
const logElement = document.createElement("p")
logElement.innerText = log
logsContainer.appendChild(log)
}
window.gamelog.clear = async function clear() {
logsContainer.innerHTML = ""
}
await initSkin()
await initSettings()
await initCapesSelector()

View File

@@ -17,22 +17,32 @@ async function login() {
const username = document.querySelector("#username").value
const password = document.querySelector("#password").value
const result = await system.call("auth::lentia", { username, password })
if (result.success == false) {
await system.call("dialog::error", {
title: result.error.error,
message: result.error.errorMessage
})
}
await processLoginResult(result)
}
function clearPassword() {
password.value = ""
}
function requestLoginWithOAuth2() {
async function requestLoginWithOAuth2() {
showFrame("oauth2")
hideInformation()
showLoadingBar()
const result = await system.call("oauth2::discord")
await processLoginResult(result, true)
}
async function processLoginResult(payload, showDefaultPage = false) {
if (payload.success == false) {
await system.call("dialog::error", {
title: payload.error.error,
message: payload.error.errorMessage
})
if (showDefaultPage) {
hideLoadingBar()
showFrame("provider")
}
}
}
hideLoadingBar()