From 464fe3ba5242bcb16e5ae3d9941f52a3b9a5ee4b Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 18:46:17 +0800 Subject: feat: update Microsoft account client ID and enhance error handling for authentication and profile fetch --- src-tauri/src/core/auth.rs | 49 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src-tauri/src/core') diff --git a/src-tauri/src/core/auth.rs b/src-tauri/src/core/auth.rs index 18e51ee..eb4f3a0 100644 --- a/src-tauri/src/core/auth.rs +++ b/src-tauri/src/core/auth.rs @@ -73,8 +73,7 @@ pub fn generate_offline_uuid(username: &str) -> String { // --- Microsoft Auth Logic --- // Constants -// Using a common public client ID for Minecraft Launchers -const CLIENT_ID: &str = "00000000-402b-802d-0000-000000000000"; +const CLIENT_ID: &str = "fe165602-5410-4441-92f7-326e10a7cb82"; const SCOPE: &str = "XboxLive.Signin offline_access openid profile email"; #[derive(Debug, Serialize, Deserialize)] @@ -215,7 +214,9 @@ pub async fn method_xbox_live(ms_access_token: &str) -> Result<(String, String), .map_err(|e| e.to_string())?; if !resp.status().is_success() { - return Err(format!("Xbox Live auth failed: {}", resp.status())); + let status = resp.status(); + let text = resp.text().await.unwrap_or_default(); + return Err(format!("Xbox Live auth failed: {} - {}", status, text)); } let xbl_resp: XboxLiveResponse = resp.json().await.map_err(|e| e.to_string())?; @@ -277,7 +278,9 @@ pub async fn login_minecraft(xsts_token: &str, uhs: &str) -> Result Result, + pub signature: Option, + pub keyId: Option, +} + +pub async fn check_ownership(mc_access_token: &str) -> Result { + let client = reqwest::Client::new(); + let url = "https://api.minecraftservices.com/entitlements/mcstore"; + + let resp = client.get(url) + .bearer_auth(mc_access_token) + .send() + .await + .map_err(|e| e.to_string())?; + + if !resp.status().is_success() { + let text = resp.text().await.unwrap_or_default(); + return Err(format!("Entitlement check failed: {} - {}", resp.status(), text)); + } + + let body: EntitlementsResponse = resp.json().await.map_err(|e| e.to_string())?; + // We look for "product_minecraft" or "game_minecraft" + let owns_game = body.items.iter().any(|e| e.name == "product_minecraft" || e.name == "game_minecraft"); + Ok(owns_game) +} -- cgit v1.2.3-70-g09d2