cargo fmt
This commit is contained in:
parent
a808fa1fe6
commit
52d247f102
4 changed files with 48 additions and 34 deletions
|
@ -8,7 +8,9 @@ use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
use steamguard::{steamapi, Confirmation, ConfirmationType, SteamGuardAccount, UserLogin, LoginError};
|
use steamguard::{
|
||||||
|
steamapi, Confirmation, ConfirmationType, LoginError, SteamGuardAccount, UserLogin,
|
||||||
|
};
|
||||||
use termion::{
|
use termion::{
|
||||||
event::{Event, Key},
|
event::{Event, Key},
|
||||||
input::TermRead,
|
input::TermRead,
|
||||||
|
@ -399,12 +401,12 @@ fn do_login(account: &mut SteamGuardAccount) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(LoginError::Need2FA) => {
|
Err(LoginError::Need2FA) => {
|
||||||
debug!("generating 2fa code and retrying");
|
debug!("generating 2fa code and retrying");
|
||||||
let server_time = steamapi::get_server_time();
|
let server_time = steamapi::get_server_time();
|
||||||
login.twofactor_code = account.generate_code(server_time);
|
login.twofactor_code = account.generate_code(server_time);
|
||||||
}
|
}
|
||||||
Err(LoginError::NeedCaptcha { captcha_gid }) => {
|
Err(LoginError::NeedCaptcha { captcha_gid }) => {
|
||||||
debug!("need captcha to log in");
|
debug!("need captcha to log in");
|
||||||
login.captcha_text = prompt_captcha_text(&captcha_gid);
|
login.captcha_text = prompt_captcha_text(&captcha_gid);
|
||||||
}
|
}
|
||||||
Err(LoginError::NeedEmail) => {
|
Err(LoginError::NeedEmail) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
pub use confirmation::{Confirmation, ConfirmationType};
|
pub use confirmation::{Confirmation, ConfirmationType};
|
||||||
pub use userlogin::{LoginError, UserLogin};
|
|
||||||
use hmacsha1::hmac_sha1;
|
use hmacsha1::hmac_sha1;
|
||||||
use log::*;
|
use log::*;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
|
@ -11,6 +10,7 @@ use reqwest::{
|
||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, convert::TryInto, thread, time};
|
use std::{collections::HashMap, convert::TryInto, thread, time};
|
||||||
|
pub use userlogin::{LoginError, UserLogin};
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -6,7 +6,7 @@ use reqwest::{
|
||||||
header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE},
|
header::{HeaderMap, HeaderName, HeaderValue, SET_COOKIE},
|
||||||
Url,
|
Url,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize, Deserializer};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
@ -48,7 +48,7 @@ where
|
||||||
{
|
{
|
||||||
// for some reason, deserializing to &str doesn't work but this does.
|
// for some reason, deserializing to &str doesn't work but this does.
|
||||||
let s: String = Deserialize::deserialize(deserializer)?;
|
let s: String = Deserialize::deserialize(deserializer)?;
|
||||||
let data: OAuthData = serde_json::from_str(s.as_str()).map_err(serde::de::Error::custom)?;
|
let data: OAuthData = serde_json::from_str(s.as_str()).map_err(serde::de::Error::custom)?;
|
||||||
Ok(Some(data))
|
Ok(Some(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,26 +294,38 @@ impl SteamApiClient {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_oauth_data_parse() {
|
fn test_oauth_data_parse() {
|
||||||
// This example is from a login response that did not contain any transfer URLs.
|
// This example is from a login response that did not contain any transfer URLs.
|
||||||
let oauth: OAuthData = serde_json::from_str("{\"steamid\":\"78562647129469312\",\"account_name\":\"feuarus\",\"oauth_token\":\"fd2fdb3d0717bcd2220d98c7ec61c7bd\",\"wgtoken\":\"72E7013D598A4F68C7E268F6FA3767D89D763732\",\"wgtoken_secure\":\"21061EA13C36D7C29812CAED900A215171AD13A2\",\"webcookie\":\"6298070A226E5DAD49938D78BCF36F7A7118FDD5\"}").unwrap();
|
let oauth: OAuthData = serde_json::from_str("{\"steamid\":\"78562647129469312\",\"account_name\":\"feuarus\",\"oauth_token\":\"fd2fdb3d0717bcd2220d98c7ec61c7bd\",\"wgtoken\":\"72E7013D598A4F68C7E268F6FA3767D89D763732\",\"wgtoken_secure\":\"21061EA13C36D7C29812CAED900A215171AD13A2\",\"webcookie\":\"6298070A226E5DAD49938D78BCF36F7A7118FDD5\"}").unwrap();
|
||||||
|
|
||||||
assert_eq!(oauth.steamid, "78562647129469312");
|
assert_eq!(oauth.steamid, "78562647129469312");
|
||||||
assert_eq!(oauth.oauth_token, "fd2fdb3d0717bcd2220d98c7ec61c7bd");
|
assert_eq!(oauth.oauth_token, "fd2fdb3d0717bcd2220d98c7ec61c7bd");
|
||||||
assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732");
|
assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732");
|
||||||
assert_eq!(oauth.wgtoken_secure, "21061EA13C36D7C29812CAED900A215171AD13A2");
|
assert_eq!(
|
||||||
assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5");
|
oauth.wgtoken_secure,
|
||||||
|
"21061EA13C36D7C29812CAED900A215171AD13A2"
|
||||||
|
);
|
||||||
|
assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_login_response_parse() {
|
fn test_login_response_parse() {
|
||||||
let result = serde_json::from_str::<LoginResponse>(include_str!("fixtures/api-responses/login-response1.json"));
|
let result = serde_json::from_str::<LoginResponse>(include_str!(
|
||||||
|
"fixtures/api-responses/login-response1.json"
|
||||||
|
));
|
||||||
|
|
||||||
assert!(matches!(result, Ok(_)), "got error: {}", result.unwrap_err());
|
assert!(
|
||||||
let resp = result.unwrap();
|
matches!(result, Ok(_)),
|
||||||
|
"got error: {}",
|
||||||
|
result.unwrap_err()
|
||||||
|
);
|
||||||
|
let resp = result.unwrap();
|
||||||
|
|
||||||
let oauth = resp.oauth.unwrap();
|
let oauth = resp.oauth.unwrap();
|
||||||
assert_eq!(oauth.steamid, "78562647129469312");
|
assert_eq!(oauth.steamid, "78562647129469312");
|
||||||
assert_eq!(oauth.oauth_token, "fd2fdb3d0717bad2220d98c7ec61c7bd");
|
assert_eq!(oauth.oauth_token, "fd2fdb3d0717bad2220d98c7ec61c7bd");
|
||||||
assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732");
|
assert_eq!(oauth.wgtoken, "72E7013D598A4F68C7E268F6FA3767D89D763732");
|
||||||
assert_eq!(oauth.wgtoken_secure, "21061EA13C36D7C29812CAED900A215171AD13A2");
|
assert_eq!(
|
||||||
assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5");
|
oauth.wgtoken_secure,
|
||||||
|
"21061EA13C36D7C29812CAED900A215171AD13A2"
|
||||||
|
);
|
||||||
|
assert_eq!(oauth.webcookie, "6298070A226E5DAD49938D78BCF36F7A7118FDD5");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crate::steamapi::{LoginResponse, RsaResponse, Session, SteamApiClient};
|
||||||
use log::*;
|
use log::*;
|
||||||
use rsa::{PublicKey, RsaPublicKey};
|
use rsa::{PublicKey, RsaPublicKey};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use crate::steamapi::{SteamApiClient, LoginResponse, RsaResponse, Session};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LoginError {
|
pub enum LoginError {
|
||||||
|
@ -77,17 +77,17 @@ impl UserLogin {
|
||||||
self.client.update_session()?;
|
self.client.update_session()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let params = hashmap!{
|
let params = hashmap! {
|
||||||
"donotcache" => format!(
|
"donotcache" => format!(
|
||||||
"{}",
|
"{}",
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs()
|
.as_secs()
|
||||||
* 1000
|
* 1000
|
||||||
),
|
),
|
||||||
"username" => self.username.clone(),
|
"username" => self.username.clone(),
|
||||||
};
|
};
|
||||||
let resp = self
|
let resp = self
|
||||||
.client
|
.client
|
||||||
.post("https://steamcommunity.com/login/getrsakey")
|
.post("https://steamcommunity.com/login/getrsakey")
|
||||||
|
|
Loading…
Reference in a new issue