diff --git a/src/auth.rs b/src/auth.rs index 49d8301..8cc320a 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -32,9 +32,17 @@ impl Api { /// Currently the only way to "authenticate" to an access token for this library. pub async fn from_interactive_url() -> Result { let login_form = Self::get_login_url_for_user().await; - dbg!(&login_form); - let callback_url = - ask_input("Enter the URL of the 404 error page after you've logged in: "); + println!("{}", "-".repeat(80)); + println!("{}", login_form.url); + println!("{}", "-".repeat(80)); + println!( + r#"Visit the URL above, and log in to your Tesla account if not already logged in. +After you log in (or already logged in), it will redirect you to a 404 error +page, where the URL will start with https://auth.tesla.com/void/callback?code=... +"# + ); + let callback_url = ask_input("Enter the whole URL of the 404 page: "); + println!(); // Newline to make the next output more separated and clear. let callback = Self::extract_callback_from_url(&callback_url)?; if callback.state != login_form.state { @@ -224,9 +232,17 @@ struct BearerTokenRequest { struct BearerTokenResponse { access_token: String, refresh_token: String, + + #[allow(dead_code)] expires_in: u32, + + #[allow(dead_code)] state: String, + + #[allow(dead_code)] token_type: String, + + #[allow(dead_code)] id_token: String, } diff --git a/src/energy.rs b/src/energy.rs index c44fb35..37482e6 100644 --- a/src/energy.rs +++ b/src/energy.rs @@ -29,9 +29,9 @@ pub struct GatewayId(String); #[derive(Debug, Clone, Deserialize)] #[serde(untagged)] pub enum EnergySite { - Vehicle(VehicleData), - Solar(SolarData), - Powerwall(PowerwallData), + Vehicle(Box), + Solar(Box), + Powerwall(Box), } /// This is assumed from https://tesla-api.timdorr.com/api-basics/products diff --git a/src/lib.rs b/src/lib.rs index 737751a..3a23beb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,7 @@ pub struct ExternalVehicleId(u64); pub struct Api { pub access_token: AccessToken, + // TODO: Why is this an Option? pub refresh_token: Option, client: Client, } diff --git a/src/main.rs b/src/main.rs index eb5db54..645a69b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ async fn main() -> miette::Result<()> { match args.command { Command::Auth { save } => { let api = Api::from_interactive_url().await?; - updated_tokens(save, &api); + print_or_save_tokens(save, &api); } Command::Refresh { refresh_token } => { let (save, refresh_token) = match refresh_token { @@ -88,7 +88,7 @@ async fn main() -> miette::Result<()> { }; let api = Api::from_refresh_token(&refresh_token).await?; - updated_tokens(save, &api); + print_or_save_tokens(save, &api); } Command::Api(api_args) => { let (access_token, refresh_token) = match &api_args.access_token { @@ -125,17 +125,20 @@ async fn main() -> miette::Result<()> { Ok(()) } -fn updated_tokens(save: bool, api: &Api) { +fn print_or_save_tokens(save: bool, api: &Api) { let access_token = api.access_token.clone(); let refresh_token = api.refresh_token.clone().unwrap(); - println!("Access token: {}", access_token); - println!("Refresh token: {}", refresh_token); + if save { Config { access_token, refresh_token, } .save(); + println!("Saved tokens to cli.json"); + } else { + println!("Access token: {}", access_token); + println!("Refresh token: {}", refresh_token); } }