refactor to use SteamApiResponse
This commit is contained in:
parent
58897b6695
commit
38f41b144f
2 changed files with 17 additions and 16 deletions
|
@ -59,7 +59,7 @@ impl AccountLinker {
|
||||||
let resp: AddAuthenticatorResponse =
|
let resp: AddAuthenticatorResponse =
|
||||||
self.client.add_authenticator(self.device_id.clone())?;
|
self.client.add_authenticator(self.device_id.clone())?;
|
||||||
|
|
||||||
match resp.response.status {
|
match resp.status {
|
||||||
29 => {
|
29 => {
|
||||||
return Err(AccountLinkError::AuthenticatorPresent);
|
return Err(AccountLinkError::AuthenticatorPresent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,9 +370,9 @@ impl SteamApiClient {
|
||||||
.text()?;
|
.text()?;
|
||||||
trace!("raw login response: {}", text);
|
trace!("raw login response: {}", text);
|
||||||
|
|
||||||
let resp: AddAuthenticatorResponse = serde_json::from_str(text.as_str())?;
|
let resp: SteamApiResponse<AddAuthenticatorResponse> = serde_json::from_str(text.as_str())?;
|
||||||
|
|
||||||
Ok(resp)
|
Ok(resp.response)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -393,7 +393,7 @@ impl SteamApiClient {
|
||||||
"authenticator_time" => time_2fa.to_string(),
|
"authenticator_time" => time_2fa.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = self
|
let resp: SteamApiResponse<FinalizeAddAuthenticatorResponse> = self
|
||||||
.post(format!(
|
.post(format!(
|
||||||
"{}/ITwoFactorService/FinalizeAddAuthenticator/v0001",
|
"{}/ITwoFactorService/FinalizeAddAuthenticator/v0001",
|
||||||
STEAM_API_BASE.to_string()
|
STEAM_API_BASE.to_string()
|
||||||
|
@ -446,12 +446,12 @@ fn test_login_response_parse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct AddAuthenticatorResponse {
|
pub struct SteamApiResponse<T> {
|
||||||
pub response: AddAuthenticatorResponseInner,
|
pub response: T
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct AddAuthenticatorResponseInner {
|
pub struct AddAuthenticatorResponse {
|
||||||
/// Shared secret between server and authenticator
|
/// Shared secret between server and authenticator
|
||||||
pub shared_secret: String,
|
pub shared_secret: String,
|
||||||
/// Authenticator serial number (unique per token)
|
/// Authenticator serial number (unique per token)
|
||||||
|
@ -477,15 +477,15 @@ pub struct AddAuthenticatorResponseInner {
|
||||||
impl AddAuthenticatorResponse {
|
impl AddAuthenticatorResponse {
|
||||||
pub fn to_steam_guard_account(&self) -> SteamGuardAccount {
|
pub fn to_steam_guard_account(&self) -> SteamGuardAccount {
|
||||||
SteamGuardAccount {
|
SteamGuardAccount {
|
||||||
shared_secret: self.response.shared_secret.clone(),
|
shared_secret: self.shared_secret.clone(),
|
||||||
serial_number: self.response.serial_number.clone(),
|
serial_number: self.serial_number.clone(),
|
||||||
revocation_code: self.response.revocation_code.clone(),
|
revocation_code: self.revocation_code.clone(),
|
||||||
uri: self.response.uri.clone(),
|
uri: self.uri.clone(),
|
||||||
server_time: self.response.server_time,
|
server_time: self.server_time,
|
||||||
account_name: self.response.account_name.clone(),
|
account_name: self.account_name.clone(),
|
||||||
token_gid: self.response.token_gid.clone(),
|
token_gid: self.token_gid.clone(),
|
||||||
identity_secret: self.response.identity_secret.clone(),
|
identity_secret: self.identity_secret.clone(),
|
||||||
secret_1: self.response.secret_1.clone(),
|
secret_1: self.secret_1.clone(),
|
||||||
fully_enrolled: false,
|
fully_enrolled: false,
|
||||||
device_id: "".into(),
|
device_id: "".into(),
|
||||||
session: None,
|
session: None,
|
||||||
|
@ -493,4 +493,5 @@ impl AddAuthenticatorResponse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct FinalizeAddAuthenticatorResponse {}
|
pub struct FinalizeAddAuthenticatorResponse {}
|
||||||
|
|
Loading…
Reference in a new issue