mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
24 lines
785 B
Rust
24 lines
785 B
Rust
use yup_oauth2::{read_authorized_user_secret, ServiceAccountImpersonationAuthenticator};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let svc_email = std::env::args().skip(1).next().unwrap();
|
|
let home = std::env::var("HOME").unwrap();
|
|
|
|
let user_secret =
|
|
read_authorized_user_secret(format!("{}/.config/gcloud/application_default_credentials.json", home))
|
|
.await
|
|
.expect("user secret");
|
|
|
|
let auth = ServiceAccountImpersonationAuthenticator::builder(user_secret, &svc_email)
|
|
.build()
|
|
.await
|
|
.expect("authenticator");
|
|
|
|
let scopes = &["https://www.googleapis.com/auth/youtube.readonly"];
|
|
match auth.token(scopes).await {
|
|
Err(e) => println!("error: {:?}", e),
|
|
Ok(t) => println!("token: {:?}", t),
|
|
}
|
|
}
|