use tokio::time::{Duration, sleep};
use gauth::serv_account::ServiceAccount;
use gauth::token_provider::AsyncTokenProvider;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let keypath = std::env::args()
.nth(1)
.expect("Provide a path to the service account key file");
let service_account =
ServiceAccount::from_file(&keypath, vec!["https://www.googleapis.com/auth/pubsub"]);
let tp = AsyncTokenProvider::new(service_account).with_interval(5);
tp.watch_updates().await;
sleep(Duration::from_secs(2)).await;
let access_token = tp.access_token()?;
println!("\n>> Access token: {}\n", access_token);
sleep(Duration::from_secs(30)).await;
Ok(())
}