🐛 fix: backport lyniths auth stuff

This commit is contained in:
Pauline 2024-07-13 15:58:59 +02:00
parent f53d3c3479
commit 818fee2592
No known key found for this signature in database
GPG key ID: 722BB181973296AE
10 changed files with 87 additions and 26 deletions

View file

@ -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" }

View file

@ -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",

View file

@ -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"

View file

@ -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<Vec<MinecraftCredentials>, String> {
minecraft::users().await.map_err(|err| err.into())
}
#[specta::specta]
#[tauri::command]
pub async fn get_user(uuid: Uuid) -> Result<MinecraftCredentials, String> {
minecraft::get_user(uuid).await.map_err(|err| err.into())
}
#[specta::specta]
#[tauri::command]
pub async fn begin_msa() -> Result<MinecraftLogin, String> {
minecraft::begin().await.map_err(|err| err.into())
}
#[specta::specta]
#[tauri::command]
pub async fn finish_msa(code: String, login: MinecraftLogin) -> Result<MinecraftCredentials, String> {
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())
}

View file

@ -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() {
</For>
</ScrollableContainer>
<div class="flex flex-row justify-end items-end mt-2">
<Button
buttonStyle="primary"
iconLeft={<UserPlus02Icon />}
children="Add Account"
onClick={() => {
// @ts-expect-error -- aa
window.doTheThing = bridge.comments.finishMsa;
bridge.commands.beginMsa().then((data) => {
if (data.status === 'ok') {
// @ts-expect-error -- aa
window.tempData = data.data;
console.log('set');
}
else {
console.log(data.error);
}
});
}}
/>
</div>
</Sidebar.Page>
);
}

View file

@ -1,5 +1,5 @@
{
"extends": "../tsconfig.base.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ESNext",
"jsx": "preserve",

View file

@ -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")]

View file

@ -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};

View file

@ -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<RequestWithDate<OAuthToken>, 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<RequestWithDate<OAuthToken>, 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)

View file

@ -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;