//! Example of how to create a mock app access token #[tokio::main] async fn main() -> anyhow::Result<()> { let _ = dotenv::dotenv(); // Eat error let mut args = std::env::args().skip(1); let reqwest = reqwest::Client::builder() .redirect(reqwest::redirect::Policy::none()) .build()?; get_env_or_arg("TWITCH_OAUTH2_URL", &mut args) .map(|t| std::env::set_var("TWITCH_OAUTH2_URL", &t)) .expect("Please set env: TWITCH_OAUTH2_URL or pass url as first argument"); let client_id = get_env_or_arg("MOCK_CLIENT_ID", &mut args) .map(twitch_oauth2::ClientId::new) .expect("Please set env: MOCK_CLIENT_ID or pass client id as an argument"); let client_secret = get_env_or_arg("MOCK_CLIENT_SECRET", &mut args) .map(twitch_oauth2::ClientSecret::new) .expect("Please set env: MOCK_CLIENT_SECRET or pass client secret as an argument"); // Getting an app access token from twitch-cli mock is almost exactly the same as in production, just using a different url. let token = twitch_oauth2::AppAccessToken::get_app_access_token( &reqwest, client_id, client_secret, vec![], ) .await?; println!( "token retrieved: {} - {:?}", token.access_token.secret(), token ); Ok(()) } fn get_env_or_arg(env: &str, args: &mut impl Iterator) -> Option { std::env::var(env).ok().or_else(|| args.next()) }