cargo fmt
This commit is contained in:
parent
c3d3f33ec3
commit
72c0acfbf1
1 changed files with 28 additions and 14 deletions
|
@ -150,7 +150,9 @@ impl SteamApiClient {
|
||||||
steam_id: data.steamid.parse().unwrap(),
|
steam_id: data.steamid.parse().unwrap(),
|
||||||
steam_login: format!("{}%7C%7C{}", data.steamid, data.wgtoken),
|
steam_login: format!("{}%7C%7C{}", data.steamid, data.wgtoken),
|
||||||
steam_login_secure: format!("{}%7C%7C{}", data.steamid, data.wgtoken_secure),
|
steam_login_secure: format!("{}%7C%7C{}", data.steamid, data.wgtoken_secure),
|
||||||
session_id: self.extract_session_id().expect("failed to extract session id from cookies"),
|
session_id: self
|
||||||
|
.extract_session_id()
|
||||||
|
.expect("failed to extract session id from cookies"),
|
||||||
web_cookie: data.webcookie.clone(),
|
web_cookie: data.webcookie.clone(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -179,7 +181,11 @@ impl SteamApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request<U: reqwest::IntoUrl + std::fmt::Display>(&self, method: reqwest::Method, url: U) -> RequestBuilder {
|
pub fn request<U: reqwest::IntoUrl + std::fmt::Display>(
|
||||||
|
&self,
|
||||||
|
method: reqwest::Method,
|
||||||
|
url: U,
|
||||||
|
) -> RequestBuilder {
|
||||||
trace!("making request: {} {}", method, url);
|
trace!("making request: {} {}", method, url);
|
||||||
self.cookies
|
self.cookies
|
||||||
.add_cookie_str("mobileClientVersion=0 (2.1.3)", &STEAM_COOKIE_URL);
|
.add_cookie_str("mobileClientVersion=0 (2.1.3)", &STEAM_COOKIE_URL);
|
||||||
|
@ -188,7 +194,10 @@ impl SteamApiClient {
|
||||||
self.cookies
|
self.cookies
|
||||||
.add_cookie_str("Steam_Language=english", &STEAM_COOKIE_URL);
|
.add_cookie_str("Steam_Language=english", &STEAM_COOKIE_URL);
|
||||||
if let Some(session) = &self.session {
|
if let Some(session) = &self.session {
|
||||||
self.cookies.add_cookie_str(format!("sessionid={}", session.session_id).as_str(), &STEAM_COOKIE_URL);
|
self.cookies.add_cookie_str(
|
||||||
|
format!("sessionid={}", session.session_id).as_str(),
|
||||||
|
&STEAM_COOKIE_URL,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.client
|
self.client
|
||||||
|
@ -377,7 +386,10 @@ impl SteamApiClient {
|
||||||
///
|
///
|
||||||
/// Host: api.steampowered.com
|
/// Host: api.steampowered.com
|
||||||
/// Endpoint: POST /ITwoFactorService/AddAuthenticator/v0001
|
/// Endpoint: POST /ITwoFactorService/AddAuthenticator/v0001
|
||||||
pub fn add_authenticator(&mut self, device_id: String) -> anyhow::Result<AddAuthenticatorResponse> {
|
pub fn add_authenticator(
|
||||||
|
&mut self,
|
||||||
|
device_id: String,
|
||||||
|
) -> anyhow::Result<AddAuthenticatorResponse> {
|
||||||
ensure!(matches!(self.session, Some(_)));
|
ensure!(matches!(self.session, Some(_)));
|
||||||
let params = hashmap! {
|
let params = hashmap! {
|
||||||
"access_token" => self.session.as_ref().unwrap().token.clone(),
|
"access_token" => self.session.as_ref().unwrap().token.clone(),
|
||||||
|
@ -432,14 +444,18 @@ impl SteamApiClient {
|
||||||
let text = resp.text()?;
|
let text = resp.text()?;
|
||||||
trace!("raw finalize authenticator response: {}", text);
|
trace!("raw finalize authenticator response: {}", text);
|
||||||
|
|
||||||
let resp: SteamApiResponse<FinalizeAddAuthenticatorResponse> = serde_json::from_str(text.as_str())?;
|
let resp: SteamApiResponse<FinalizeAddAuthenticatorResponse> =
|
||||||
|
serde_json::from_str(text.as_str())?;
|
||||||
|
|
||||||
return Ok(resp.response);
|
return Ok(resp.response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Host: api.steampowered.com
|
/// Host: api.steampowered.com
|
||||||
/// Endpoint: POST /ITwoFactorService/RemoveAuthenticator/v0001
|
/// Endpoint: POST /ITwoFactorService/RemoveAuthenticator/v0001
|
||||||
pub fn remove_authenticator(&self, revocation_code: String) -> anyhow::Result<RemoveAuthenticatorResponse> {
|
pub fn remove_authenticator(
|
||||||
|
&self,
|
||||||
|
revocation_code: String,
|
||||||
|
) -> anyhow::Result<RemoveAuthenticatorResponse> {
|
||||||
let params = hashmap! {
|
let params = hashmap! {
|
||||||
"steamid" => self.session.as_ref().unwrap().steam_id.to_string(),
|
"steamid" => self.session.as_ref().unwrap().steam_id.to_string(),
|
||||||
"steamguard_scheme" => "2".into(),
|
"steamguard_scheme" => "2".into(),
|
||||||
|
@ -458,7 +474,8 @@ impl SteamApiClient {
|
||||||
let text = resp.text()?;
|
let text = resp.text()?;
|
||||||
trace!("raw remove authenticator response: {}", text);
|
trace!("raw remove authenticator response: {}", text);
|
||||||
|
|
||||||
let resp: SteamApiResponse<RemoveAuthenticatorResponse> = serde_json::from_str(text.as_str())?;
|
let resp: SteamApiResponse<RemoveAuthenticatorResponse> =
|
||||||
|
serde_json::from_str(text.as_str())?;
|
||||||
|
|
||||||
return Ok(resp.response);
|
return Ok(resp.response);
|
||||||
}
|
}
|
||||||
|
@ -520,10 +537,7 @@ fn test_login_response_parse_missing_webcookie() {
|
||||||
assert_eq!(oauth.steamid, "92591609556178617");
|
assert_eq!(oauth.steamid, "92591609556178617");
|
||||||
assert_eq!(oauth.oauth_token, "1cc83205dab2979e558534dab29f6f3aa");
|
assert_eq!(oauth.oauth_token, "1cc83205dab2979e558534dab29f6f3aa");
|
||||||
assert_eq!(oauth.wgtoken, "3EDA9DEF07D7B39361D95203525D8AFE82A");
|
assert_eq!(oauth.wgtoken, "3EDA9DEF07D7B39361D95203525D8AFE82A");
|
||||||
assert_eq!(
|
assert_eq!(oauth.wgtoken_secure, "F31641B9AFC2F8B0EE7B6F44D7E73EA3FA48");
|
||||||
oauth.wgtoken_secure,
|
|
||||||
"F31641B9AFC2F8B0EE7B6F44D7E73EA3FA48"
|
|
||||||
);
|
|
||||||
assert_eq!(oauth.webcookie, "");
|
assert_eq!(oauth.webcookie, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,7 +609,7 @@ pub struct FinalizeAddAuthenticatorResponse {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct RemoveAuthenticatorResponse {
|
pub struct RemoveAuthenticatorResponse {
|
||||||
pub success: bool
|
pub success: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_json_string_as_number<'de, D>(deserializer: D) -> Result<u64, D::Error>
|
fn parse_json_string_as_number<'de, D>(deserializer: D) -> Result<u64, D::Error>
|
||||||
|
|
Loading…
Reference in a new issue