Skip to content

Commit 0b6b833

Browse files
committed
auth is working, bearer support still missing
1 parent 45b34d4 commit 0b6b833

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

src-tauri/src/account.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ impl Account {
305305
None
306306
}
307307

308+
pub fn check_change_eligibility(&self) -> Option<bool> {
309+
let client = ClientBuilder::new().build().ok()?;
310+
let res = client
311+
.get("https://api.minecraftservices.com/minecraft/profile/namechange")
312+
.header(AUTHORIZATION, format!("Bearer {}", self.token))
313+
.send()
314+
.ok()?;
315+
let data = res.json::<Value>().ok()?;
316+
data.get("nameChangeAllowed").and_then(|v| v.as_bool())
317+
}
318+
308319
pub fn opt_reauth(&mut self, proxy: Option<Proxy>) -> Option<()> {
309320
if self.time > Utc::now() {
310321
return Some(());
@@ -322,6 +333,7 @@ impl Account {
322333
Color::from((0, 255, 0)),
323334
&format!("Reauthed {}.", self.user),
324335
);
336+
self.time = Utc::now() + Duration::hours(23);
325337
Some(())
326338
}
327339

@@ -338,7 +350,7 @@ impl Account {
338350

339351
let Ok(res) = client
340352
.post("https://login.live.com/oauth20_token.srf")
341-
.header("Content-Type", "application/x-www-form-urlencode")
353+
.header("Content-Type", "application/x-www-form-urlencoded")
342354
.body(body)
343355
.send()
344356
else {
@@ -383,12 +395,12 @@ impl Account {
383395

384396
let body = json!({
385397
"Properties": {
386-
"Authmethod": "RPS",
387-
"Sitename": "user.auth.xboxlive.com",
388-
"Rpsticket": access_token,
398+
"AuthMethod": "RPS",
399+
"SiteName": "user.auth.xboxlive.com",
400+
"RpsTicket": access_token,
389401
},
390-
"Relyingparty": "http://auth.xboxlive.com",
391-
"Tokentype": "JWT",
402+
"RelyingParty": "http://auth.xboxlive.com",
403+
"TokenType": "JWT",
392404
});
393405

394406
let mut headers = HeaderMap::new();
@@ -472,7 +484,7 @@ impl Account {
472484
}
473485
}
474486

475-
let Some(uhs_verify) = body
487+
let Some(uhs_verify) = data
476488
.get("DisplayClaims")
477489
.and_then(|v| v.get("xui"))
478490
.and_then(|v| v.get(0))
@@ -486,7 +498,7 @@ impl Account {
486498
return Err("uhs tokens don't match!".to_string());
487499
}
488500

489-
let Some(token) = body.get("Token").and_then(|v| v.as_str()) else {
501+
let Some(token) = data.get("Token").and_then(|v| v.as_str()) else {
490502
return Err("No token found in xbox live auth body.".to_string());
491503
};
492504

@@ -716,7 +728,7 @@ impl Account {
716728
}
717729
}
718730

719-
let Some(uhs_verify) = body
731+
let Some(uhs_verify) = data
720732
.get("DisplayClaims")
721733
.and_then(|v| v.get("xui"))
722734
.and_then(|v| v.get(0))
@@ -730,12 +742,12 @@ impl Account {
730742
return Err("uhs tokens don't match!".to_string());
731743
}
732744

733-
let Some(token) = body.get("Token").and_then(|v| v.as_str()) else {
745+
let Some(token) = data.get("Token").and_then(|v| v.as_str()) else {
734746
return Err("No token found in xbox live auth body.".to_string());
735747
};
736748

737749
let body = json!({
738-
"identityToken" : dbg!(format!("XBL3.0 x={};{}", uhs, token)),
750+
"identityToken" : format!("XBL3.0 x={};{}", uhs, token),
739751
"ensureLegacyEnabled": true
740752
});
741753

@@ -747,12 +759,9 @@ impl Account {
747759
return Err("Failed to send request for bearer!".to_string());
748760
};
749761

750-
println!("{}", res.text().unwrap());
751-
752-
/* let Ok(data) = res.json::<Value>() else {
762+
let Ok(data) = res.json::<Value>() else {
753763
return Err("Failed to parse response for bearer!".to_string());
754-
}; */
755-
let data = Value::Null;
764+
};
756765

757766
let Some(bearer) = data.get("access_token").and_then(|v| v.as_str()) else {
758767
return Err("Failed to extract bearer!".to_string());

src-tauri/src/sniper.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
146146
return;
147147
}
148148
};
149-
let claim = match Account::new(user.to_string(), pass.to_string(), None) {
149+
let mut claim = match Account::new(user.to_string(), pass.to_string(), None) {
150150
Some(acc) => acc,
151151
_ => {
152152
log(
@@ -159,6 +159,30 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
159159
return;
160160
}
161161
};
162+
match claim.check_change_eligibility() {
163+
Some(b) => {
164+
if !b {
165+
log(
166+
"ERROR",
167+
Color::from((255, 0, 0)),
168+
"Claimer can't namechange!",
169+
);
170+
alert("Claimer can't namechange!");
171+
app_handle().emit("stop", true).unwrap();
172+
return;
173+
}
174+
}
175+
None => {
176+
log(
177+
"ERROR",
178+
Color::from((255, 0, 0)),
179+
"Failed to check if claimer can change name!",
180+
);
181+
alert("Failed to check if claimer can change name!");
182+
app_handle().emit("stop", true).unwrap();
183+
return;
184+
}
185+
}
162186
let window = match app_handle().get_webview_window("main") {
163187
Some(w) => w,
164188
_ => {
@@ -279,7 +303,6 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
279303
if available {
280304
claim_pass.claim(name_pass, proxy_pass.clone());
281305
app_handle().emit("stop", true).unwrap();
282-
set_thread_status(false);
283306
return;
284307
} else {
285308
log(
@@ -312,6 +335,16 @@ fn snipe(name: String, accounts: Vec<String>, claim: String, proxies: Vec<String
312335
});
313336

314337
proxy_list.push_back(proxy);
338+
if claim.opt_reauth(None).is_none() {
339+
log(
340+
"ERROR",
341+
Color::from((255, 0, 0)),
342+
"Failed to reauth claimer!",
343+
);
344+
alert("Failed to reauth claimer!");
345+
app_handle().emit("stop", true).unwrap();
346+
return;
347+
}
315348
sleep(Duration::from_secs_f32(rl));
316349
}
317350
}

0 commit comments

Comments
 (0)