From 1824b8c2297bb90d6c92482ab09ded5046bc0596 Mon Sep 17 00:00:00 2001 From: Blake Mealey Date: Sun, 29 Oct 2023 14:44:37 -0500 Subject: [PATCH] fix(rbx_cookie): get cookie from userid-postfixed credential on windows --- mantle/rbx_auth/src/main.rs | 8 ++------ mantle/rbx_cookie/src/lib.rs | 35 +++++++++++++++++++++++++++-------- mantle/rbx_cookie/src/main.rs | 8 ++------ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/mantle/rbx_auth/src/main.rs b/mantle/rbx_auth/src/main.rs index 2c90c1e..a7ba836 100644 --- a/mantle/rbx_auth/src/main.rs +++ b/mantle/rbx_auth/src/main.rs @@ -15,14 +15,10 @@ async fn main() { Arg::with_name("format") .long("format") .short("f") - .help("The format of the output. Either 'table' (default) or 'json'") + .help("The format of the output.") .value_name("FORMAT") .takes_value(true) - .validator(|value| match value.as_str() { - "table" => Ok(()), - "json" => Ok(()), - _ => Err("Expected either 'table' or 'json'".to_owned()), - }) + .possible_values(&["table", "json"]) .default_value("table"), ) .arg( diff --git a/mantle/rbx_cookie/src/lib.rs b/mantle/rbx_cookie/src/lib.rs index 4f18c3e..a8fdafe 100644 --- a/mantle/rbx_cookie/src/lib.rs +++ b/mantle/rbx_cookie/src/lib.rs @@ -43,17 +43,36 @@ fn from_environment() -> Option { #[cfg(target_os = "windows")] fn from_roblox_studio() -> Option { + // First try the userid postfixed cookie trace!("Attempting to load cookie from Windows Credentials."); - let cookie = wincred::get(&format!( - "https://www.roblox.com:RobloxStudioAuth{}", - COOKIE_NAME - )) - .ok()?; - - info!("Loaded cookie from Windows Credentials."); + let user_id = wincred::get(&format!("https://www.roblox.com:RobloxStudioAuthuserid")).ok(); + let cookie = user_id.as_ref().and_then(|user_id| { + wincred::get(&format!( + "https://www.roblox.com:RobloxStudioAuth{}{}", + COOKIE_NAME, user_id + )) + .ok() + }); + + if cookie.is_some() { + info!( + "Loaded cookie from Windows Credentials (user_id: {}).", + user_id.unwrap() + ); + cookie + } else { + // Fallback to the old cookie + trace!("Attempting to load cookie from Windows Credentials (legacy)."); - Some(cookie) + let cookie = wincred::get(&format!( + "https://www.roblox.com:RobloxStudioAuth{}", + COOKIE_NAME + )) + .ok()?; + info!("Loaded cookie from Windows Credentials (legacy)."); + Some(cookie) + } } #[cfg(target_os = "macos")] diff --git a/mantle/rbx_cookie/src/main.rs b/mantle/rbx_cookie/src/main.rs index e6cd6bb..edf5978 100644 --- a/mantle/rbx_cookie/src/main.rs +++ b/mantle/rbx_cookie/src/main.rs @@ -11,14 +11,10 @@ fn main() { Arg::with_name("format") .long("format") .short("f") - .help("The format of the output. Either 'value' (default) or 'cookie'") + .help("The format of the output.") .value_name("FORMAT") .takes_value(true) - .validator(|value| match value.as_str() { - "value" => Ok(()), - "cookie" => Ok(()), - _ => Err("Expected either 'value' or 'cookie'".to_owned()), - }) + .possible_values(&["value", "cookie"]) .default_value("value"), ) .arg(