fixed session not being transfered to AccountLinker
This commit is contained in:
parent
afafe44d60
commit
b2414e0c33
3 changed files with 14 additions and 11 deletions
|
@ -26,8 +26,8 @@ impl AccountLinker {
|
||||||
account: None,
|
account: None,
|
||||||
finalized: false,
|
finalized: false,
|
||||||
sent_confirmation_email: false,
|
sent_confirmation_email: false,
|
||||||
session: session,
|
session: session.clone(),
|
||||||
client: SteamApiClient::new(),
|
client: SteamApiClient::new(Some(session)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ pub struct SteamApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SteamApiClient {
|
impl SteamApiClient {
|
||||||
pub fn new() -> SteamApiClient {
|
pub fn new(session: Option<Session>) -> SteamApiClient {
|
||||||
SteamApiClient {
|
SteamApiClient {
|
||||||
cookies: reqwest::cookie::Jar::default(),
|
cookies: reqwest::cookie::Jar::default(),
|
||||||
client: reqwest::blocking::ClientBuilder::new()
|
client: reqwest::blocking::ClientBuilder::new()
|
||||||
|
@ -139,17 +139,18 @@ impl SteamApiClient {
|
||||||
}.into_iter()))
|
}.into_iter()))
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
session: None,
|
session: session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_session(&self, data: &OAuthData) -> Session {
|
fn build_session(&self, data: &OAuthData) -> Session {
|
||||||
|
trace!("SteamApiClient::build_session");
|
||||||
return Session {
|
return Session {
|
||||||
token: data.oauth_token.clone(),
|
token: data.oauth_token.clone(),
|
||||||
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().unwrap(),
|
session_id: self.extract_session_id().expect("failed to extract session id from cookies"),
|
||||||
web_cookie: data.webcookie.clone(),
|
web_cookie: data.webcookie.clone(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -249,6 +250,7 @@ impl SteamApiClient {
|
||||||
.post("https://steamcommunity.com/login/dologin")
|
.post("https://steamcommunity.com/login/dologin")
|
||||||
.form(¶ms)
|
.form(¶ms)
|
||||||
.send()?;
|
.send()?;
|
||||||
|
self.save_cookies_from_response(&resp);
|
||||||
let text = resp.text()?;
|
let text = resp.text()?;
|
||||||
trace!("raw login response: {}", text);
|
trace!("raw login response: {}", text);
|
||||||
|
|
||||||
|
@ -351,7 +353,7 @@ impl SteamApiClient {
|
||||||
///
|
///
|
||||||
/// Host: api.steampowered.com
|
/// Host: api.steampowered.com
|
||||||
/// Endpoint: POST /ITwoFactorService/AddAuthenticator/v0001
|
/// Endpoint: POST /ITwoFactorService/AddAuthenticator/v0001
|
||||||
pub fn add_authenticator(&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(),
|
||||||
|
@ -361,15 +363,16 @@ impl SteamApiClient {
|
||||||
"sms_phone_id" => "1".into(),
|
"sms_phone_id" => "1".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let text = self
|
let resp = self
|
||||||
.post(format!(
|
.post(format!(
|
||||||
"{}/ITwoFactorService/AddAuthenticator/v0001",
|
"{}/ITwoFactorService/AddAuthenticator/v0001",
|
||||||
STEAM_API_BASE.to_string()
|
STEAM_API_BASE.to_string()
|
||||||
))
|
))
|
||||||
.form(¶ms)
|
.form(¶ms)
|
||||||
.send()?
|
.send()?;
|
||||||
.text()?;
|
self.save_cookies_from_response(&resp);
|
||||||
trace!("raw login response: {}", text);
|
let text = resp.text()?;
|
||||||
|
trace!("raw add authenticator response: {}", text);
|
||||||
|
|
||||||
let resp: SteamApiResponse<AddAuthenticatorResponse> = serde_json::from_str(text.as_str())?;
|
let resp: SteamApiResponse<AddAuthenticatorResponse> = serde_json::from_str(text.as_str())?;
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl UserLogin {
|
||||||
twofactor_code: String::from(""),
|
twofactor_code: String::from(""),
|
||||||
email_code: String::from(""),
|
email_code: String::from(""),
|
||||||
steam_id: 0,
|
steam_id: 0,
|
||||||
client: SteamApiClient::new(),
|
client: SteamApiClient::new(None),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue