diff --git a/theseus/Cargo.toml b/theseus/Cargo.toml index c071b9be8..d0a08bf06 100644 --- a/theseus/Cargo.toml +++ b/theseus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "theseus" -version = "0.5.2" +version = "0.5.3" authors = ["Jai A "] edition = "2018" diff --git a/theseus/src/api/hydra/mod.rs b/theseus/src/api/hydra/mod.rs index 8de3c862c..a6be05718 100644 --- a/theseus/src/api/hydra/mod.rs +++ b/theseus/src/api/hydra/mod.rs @@ -1,7 +1,7 @@ pub mod complete; pub mod init; pub mod refresh; -mod stages; +pub(crate) mod stages; use serde::Deserialize; diff --git a/theseus/src/launcher/auth.rs b/theseus/src/launcher/auth.rs index c42b8cc76..cc9304d91 100644 --- a/theseus/src/launcher/auth.rs +++ b/theseus/src/launcher/auth.rs @@ -7,6 +7,8 @@ use chrono::{prelude::*, Duration}; use serde::{Deserialize, Serialize}; +use crate::api::hydra::stages::{bearer_token, xbl_signin, xsts_token}; + // Login information #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Credentials { @@ -45,12 +47,39 @@ pub async fn refresh_credentials( credentials: &mut Credentials, _semaphore: &FetchSemaphore, ) -> crate::Result<()> { - let res = + let oauth = hydra::refresh::refresh(credentials.refresh_token.clone()).await?; - credentials.access_token = res.access_token; - credentials.refresh_token = res.refresh_token; - credentials.expires = Utc::now() + Duration::seconds(res.expires_in); + let xbl_token = xbl_signin::login_xbl(&oauth.access_token).await?; + + // Get xsts token from xbl token + let xsts_response = xsts_token::fetch_token(&xbl_token.token).await?; + + match xsts_response { + xsts_token::XSTSResponse::Unauthorized(err) => { + return Err(crate::ErrorKind::HydraError(format!( + "Error getting XBox Live token: {}", + err + )) + .as_error()) + } + xsts_token::XSTSResponse::Success { token: xsts_token } => { + let bearer_token = + bearer_token::fetch_bearer(&xsts_token, &xbl_token.uhs) + .await + .map_err(|err| { + crate::ErrorKind::HydraError(format!( + "Error getting bearer token: {}", + err + )) + })?; + + credentials.access_token = bearer_token; + credentials.refresh_token = oauth.refresh_token; + credentials.expires = + Utc::now() + Duration::seconds(oauth.expires_in); + } + } Ok(()) } diff --git a/theseus_cli/Cargo.toml b/theseus_cli/Cargo.toml index 7576808ad..dbd711776 100644 --- a/theseus_cli/Cargo.toml +++ b/theseus_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "theseus_cli" -version = "0.5.2" +version = "0.5.3" authors = ["Jai A "] edition = "2018" diff --git a/theseus_gui/package.json b/theseus_gui/package.json index 9a2bd45e4..9f174da93 100644 --- a/theseus_gui/package.json +++ b/theseus_gui/package.json @@ -1,7 +1,7 @@ { "name": "theseus_gui", "private": true, - "version": "0.5.2", + "version": "0.5.3", "type": "module", "scripts": { "dev": "vite", diff --git a/theseus_gui/src-tauri/Cargo.toml b/theseus_gui/src-tauri/Cargo.toml index e8f371104..3eec861ff 100644 --- a/theseus_gui/src-tauri/Cargo.toml +++ b/theseus_gui/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "theseus_gui" -version = "0.5.2" +version = "0.5.3" description = "A Tauri App" authors = ["you"] license = "" diff --git a/theseus_gui/src-tauri/tauri.conf.json b/theseus_gui/src-tauri/tauri.conf.json index 9297c8a22..276525243 100644 --- a/theseus_gui/src-tauri/tauri.conf.json +++ b/theseus_gui/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Modrinth App", - "version": "0.5.2" + "version": "0.5.3" }, "tauri": { "allowlist": {