From 818fee2592674af2a98918b3df4060aedbc53da7 Mon Sep 17 00:00:00 2001 From: Pauline Date: Sat, 13 Jul 2024 15:58:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20backport=20lyniths=20auth?= =?UTF-8?q?=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 6 ++- apps/desktop/src-tauri/build.rs | 7 +++- .../permissions/onelauncher/default.toml | 7 +++- apps/desktop/src-tauri/src/api/commands.rs | 41 +++++++++++++++++-- .../pages/settings/game/SettingsAccounts.tsx | 24 ++++++++++- apps/desktop/tsconfig.json | 2 +- crates/core/src/constants.rs | 6 +-- crates/core/src/store/metadata.rs | 8 +++- crates/core/src/store/minecraft.rs | 11 ++--- crates/core/src/store/package.rs | 1 - 10 files changed, 87 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b0048ed3..a6c399a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,9 @@ specta = { git = "https://github.com/oscartbeaumont/specta", rev = "13fd87c6a1e5 "chrono", "uuid", "serde", - "serde_json" + "serde_json", + "derive", + "function" ] } # tauri-specta is updated via crates.io tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta", rev = "a49885967adc01c80e33962e3ecac25fe7497839", features = [ @@ -65,7 +67,7 @@ prisma-client-rust-cli = { git = "https://github.com/brendonovich/prisma-client- prisma-client-rust-sdk = { git = "https://github.com/brendonovich/prisma-client-rust", rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab", features = [ "sqlite" ], default-features = false } # interpulse is updated on the main branch -interpulse = { git = "https://github.com/pulseflow/workers", rev = "abc6fb0f263a6f3a5e1fa5810f7ee9d2ad61e8b8", features = [ "specta" ] } +interpulse = { git = "https://github.com/pulseflow/workers", rev = "98f7a1135ac75f9734172595cb86379b1c416d18", features = [ "specta" ] } # all other dependencies are updated to latest crates.io release channel tracing = { version = "0.1" } diff --git a/apps/desktop/src-tauri/build.rs b/apps/desktop/src-tauri/build.rs index ff06c3f1..4e7b8824 100644 --- a/apps/desktop/src-tauri/build.rs +++ b/apps/desktop/src-tauri/build.rs @@ -5,8 +5,11 @@ fn main() { .plugin( "onelauncher", tauri_build::InlinedPlugin::new().commands(&[ - "login_msa", - "refresh_client_manager", + "begin_msa", + "finish_msa", + "get_users", + "get_user", + "remove_user", "launch_cluster", "create_cluster", "get_clusters", diff --git a/apps/desktop/src-tauri/permissions/onelauncher/default.toml b/apps/desktop/src-tauri/permissions/onelauncher/default.toml index 16d1a80a..5baddb3e 100644 --- a/apps/desktop/src-tauri/permissions/onelauncher/default.toml +++ b/apps/desktop/src-tauri/permissions/onelauncher/default.toml @@ -1,13 +1,16 @@ [default] description = "Default permissions for the plugin" permissions = [ - "allow-refresh-client-manager", + "allow-begin-msa", + "allow-finish-msa", + "allow-get-users", + "allow-get-user", + "allow-remove-user", "allow-launch-cluster", "allow-create-cluster", "allow-get-clusters", "allow-get-cluster", "allow-get-manifest", - "allow-login-msa", "allow-get-settings", "allow-set-settings", "allow-get-program-info" diff --git a/apps/desktop/src-tauri/src/api/commands.rs b/apps/desktop/src-tauri/src/api/commands.rs index fb5bd44f..60a37b4c 100644 --- a/apps/desktop/src-tauri/src/api/commands.rs +++ b/apps/desktop/src-tauri/src/api/commands.rs @@ -4,9 +4,9 @@ use std::str::FromStr; use chrono::DateTime; use onelauncher::constants::{NATIVE_ARCH, TARGET_OS, VERSION}; -use onelauncher::data::{ClusterMeta, Loader, PackageData, Settings}; -use onelauncher::store::{Cluster, ClusterPath}; -use onelauncher::{cluster, settings}; +use onelauncher::data::{ClusterMeta, Loader, MinecraftCredentials, PackageData, Settings}; +use onelauncher::store::{Cluster, ClusterPath, MinecraftLogin}; +use onelauncher::{cluster, minecraft, settings}; use serde::{Deserialize, Serialize}; use specta::Type; use uuid::Uuid; @@ -21,6 +21,11 @@ macro_rules! collect_commands { .bigint(specta::ts::BigIntExportBehavior::BigInt), ) .commands(tauri_specta::collect_commands![ + begin_msa, + finish_msa, + get_users, + get_user, + remove_user, create_cluster, get_cluster, get_clusters, @@ -165,3 +170,33 @@ pub fn get_program_info() -> ProgramInfo { arch: NATIVE_ARCH.into(), } } + +#[specta::specta] +#[tauri::command] +pub async fn get_users() -> Result, String> { + minecraft::users().await.map_err(|err| err.into()) +} + +#[specta::specta] +#[tauri::command] +pub async fn get_user(uuid: Uuid) -> Result { + minecraft::get_user(uuid).await.map_err(|err| err.into()) +} + +#[specta::specta] +#[tauri::command] +pub async fn begin_msa() -> Result { + minecraft::begin().await.map_err(|err| err.into()) +} + +#[specta::specta] +#[tauri::command] +pub async fn finish_msa(code: String, login: MinecraftLogin) -> Result { + minecraft::finish(code.as_str(), login).await.map_err(|err| err.into()) +} + +#[specta::specta] +#[tauri::command] +pub async fn remove_user(uuid: Uuid) -> Result<(), String> { + minecraft::remove_user(uuid).await.map_err(|err| err.into()) +} diff --git a/apps/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx b/apps/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx index cb3429f4..e4f9d629 100644 --- a/apps/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx +++ b/apps/desktop/src/ui/pages/settings/game/SettingsAccounts.tsx @@ -1,5 +1,6 @@ -import { ChevronRightIcon, InfoCircleIcon } from '@untitled-theme/icons-solid'; +import { ChevronRightIcon, InfoCircleIcon, UserPlus02Icon } from '@untitled-theme/icons-solid'; import { For, Show, createSignal, mergeProps } from 'solid-js'; +import { bridge } from '~imports'; import Button from '~ui/components/base/Button'; import Tooltip from '~ui/components/base/Tooltip'; import PlayerHead from '~ui/components/game/PlayerHead'; @@ -48,6 +49,27 @@ function SettingsAccounts() { +
+
); } diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index a6820e81..a5b40d95 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../tsconfig.base.json", + "extends": "../../tsconfig.base.json", "compilerOptions": { "target": "ESNext", "jsx": "preserve", diff --git a/crates/core/src/constants.rs b/crates/core/src/constants.rs index 32830f0a..d7b4c721 100644 --- a/crates/core/src/constants.rs +++ b/crates/core/src/constants.rs @@ -13,11 +13,7 @@ pub const DISCORD_RPC_CLIENT_ID: &str = "1234567890000000"; // Microsoft Authentication pub const CLIENT_ID: &str = "9419b7ee-1448-4d1b-b52a-550d8f36ab56"; -pub const MSA_PORT: u16 = 13523; - -// Minecraft -pub const MINECRAFT_VERSIONS_MANIFEST: &str = - "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"; +pub const MICROSOFT_CLIENT_ID: &str = ""; // OS constants which match Minecraft's/Mojang's scheme #[cfg(target_os = "windows")] diff --git a/crates/core/src/store/metadata.rs b/crates/core/src/store/metadata.rs index a0fe2bd2..64deb2e6 100644 --- a/crates/core/src/store/metadata.rs +++ b/crates/core/src/store/metadata.rs @@ -1,8 +1,12 @@ //! Handles fetching metadata via interpulse. -use interpulse::api::minecraft::{fetch_version_manifest, VersionManifest as MinecraftManifest}; +use interpulse::api::minecraft::{ + // fetch_version_manifest, + VersionManifest as MinecraftManifest +}; use interpulse::api::modded::{ - fetch_manifest as fetch_modded_manifest, Manifest as ModdedManifest, + // fetch_manifest as fetch_modded_manifest, + Manifest as ModdedManifest, }; use serde::{Deserialize, Serialize}; diff --git a/crates/core/src/store/minecraft.rs b/crates/core/src/store/minecraft.rs index 161a47ab..059e4f26 100644 --- a/crates/core/src/store/minecraft.rs +++ b/crates/core/src/store/minecraft.rs @@ -310,9 +310,6 @@ impl MinecraftState { } } -// TODO: get MICROSOFT_CLIENT_ID -/// Publically used Minecraft client ID for OneLauncher. -const MICROSOFT_CLIENT_ID: &str = ""; /// Microsoft login redirect URI. const REDIRECT_URL: &str = "https://login.live.com/oauth20_desktop.srf"; /// Microsoft login xboxlive scopes to get tokens. @@ -451,7 +448,7 @@ async fn sisu_authenticate( "https://sisu.xboxlive.com/authenticate", "/authenticate", json!({ - "AppId": MICROSOFT_CLIENT_ID, + "AppId": crate::constants::MICROSOFT_CLIENT_ID, "DeviceToken": token, "Offers": [SCOPES], "Query": { @@ -504,7 +501,7 @@ async fn oauth_token( verify: &str, ) -> Result, MinecraftAuthError> { let mut query = HashMap::new(); - query.insert("client_id", MICROSOFT_CLIENT_ID); + query.insert("client_id", crate::constants::MICROSOFT_CLIENT_ID); query.insert("code", code); query.insert("code_verifier", verify); query.insert("grant_type", "authorization_code"); @@ -552,7 +549,7 @@ async fn oauth_refresh( refresh_token: &str, ) -> Result, MinecraftAuthError> { let mut query = HashMap::new(); - query.insert("client_id", MICROSOFT_CLIENT_ID); + query.insert("client_id", crate::constants::MICROSOFT_CLIENT_ID); query.insert("refresh_token", refresh_token); query.insert("grant_type", "refresh_token"); query.insert("redirect_uri", REDIRECT_URL); @@ -619,7 +616,7 @@ async fn sisu_authorize( "/authorize", json!({ "AccessToken": format!("t={access_token}"), - "AppId": MICROSOFT_CLIENT_ID, + "AppId": crate::constants::MICROSOFT_CLIENT_ID, "DeviceToken": device_token, "ProofKey": { // kibty (kty) diff --git a/crates/core/src/store/package.rs b/crates/core/src/store/package.rs index 26002a45..67a37810 100644 --- a/crates/core/src/store/package.rs +++ b/crates/core/src/store/package.rs @@ -5,7 +5,6 @@ use async_zip::tokio::read::fs::ZipFileReader; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use sha2::Digest; -use specta::specta; use std::collections::HashMap; use std::path::{Path, PathBuf}; use tokio::io::AsyncReadExt;