Skip to content

Commit

Permalink
Support list phone numbers 201
Browse files Browse the repository at this point in the history
  • Loading branch information
TaeHagen authored and Dadoum committed May 5, 2024
1 parent e55592a commit 311c105
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions icloud-auth/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use cbc::cipher::{BlockDecryptMut, KeyIvInit};
use hmac::{Hmac, Mac};
use omnisette::AnisetteConfiguration;
use reqwest::{
Client, ClientBuilder, Response,
header::{HeaderMap, HeaderName, HeaderValue},
Certificate,
header::{HeaderMap, HeaderName, HeaderValue}, Certificate, Client, ClientBuilder, Proxy, Response
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -134,6 +132,7 @@ pub struct VerifyBody {
security_code: Option<VerifyCode>
}

#[repr(C)]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TrustedPhoneNumber {
Expand All @@ -153,6 +152,8 @@ pub struct AuthenticationExtras {
pub recovery_web_url: Option<String>,
pub repair_phone_number_url: Option<String>,
pub repair_phone_number_web_url: Option<String>,
#[serde(skip)]
pub new_state: Option<LoginState>,
}

// impl Send2FAToDevices {
Expand Down Expand Up @@ -570,12 +571,24 @@ impl AppleAccount {
pub async fn get_auth_extras(&self) -> Result<AuthenticationExtras, Error> {
let headers = self.build_2fa_headers(true);

Ok(self.client
let req = self.client
.get("https://gsa.apple.com/auth")
.headers(headers.await)
.header("Accept", "application/json")
.send().await?
.json::<AuthenticationExtras>().await?)
.send().await?;
let status = req.status().as_u16();
let mut new_state = req.json::<AuthenticationExtras>().await?;
if status == 201 {
new_state.new_state = Some(LoginState::NeedsSMS2FAVerification(VerifyBody {
phone_number: PhoneNumber {
id: new_state.trusted_phone_numbers.first().unwrap().id
},
mode: "sms".to_string(),
security_code: None
}));
}

Ok(new_state)
}

pub async fn verify_2fa(&self, code: String) -> Result<LoginState, Error> {
Expand Down

0 comments on commit 311c105

Please sign in to comment.