Skip to content

Commit

Permalink
fix(rbx_cookie): get cookie from userid-postfixed credential on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
blake-mealey committed Oct 29, 2023
1 parent 467957e commit 1824b8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
8 changes: 2 additions & 6 deletions mantle/rbx_auth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 27 additions & 8 deletions mantle/rbx_cookie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,36 @@ fn from_environment() -> Option<String> {

#[cfg(target_os = "windows")]
fn from_roblox_studio() -> Option<String> {
// 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")]
Expand Down
8 changes: 2 additions & 6 deletions mantle/rbx_cookie/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

1 comment on commit 1824b8c

@vercel
Copy link

@vercel vercel bot commented on 1824b8c Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.