refactor: read client_secret.json from disk instead of env vars

This commit is contained in:
Ruben Rosario
2026-06-21 10:23:25 +01:00
parent 9da086b7be
commit ae9910bcbc
2 changed files with 46 additions and 22 deletions
+6 -15
View File
@@ -1,10 +1,9 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use reqwest::Client;
use yup_oauth2::{
authenticator::Authenticator, hyper::client::connect::HttpConnector,
hyper_rustls::HttpsConnector, ApplicationSecret, InstalledFlowAuthenticator,
InstalledFlowReturnMethod,
hyper_rustls::HttpsConnector, InstalledFlowAuthenticator, InstalledFlowReturnMethod,
};
use crate::domain::models::*;
@@ -37,7 +36,7 @@ pub struct ApiClient {
const SCOPES: &[&str] = &["https://www.googleapis.com/auth/tasks"];
impl ApiClient {
pub async fn new(client_id: String, client_secret: String) -> Result<Self, ApiError> {
pub async fn new(secret_path: impl AsRef<Path>) -> Result<Self, ApiError> {
let token_path = dirs::config_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("task_app")
@@ -47,17 +46,9 @@ impl ApiClient {
std::fs::create_dir_all(parent).ok();
}
let secret = ApplicationSecret {
client_id,
client_secret,
auth_uri: "https://accounts.google.com/o/oauth2/v2/auth".to_string(),
token_uri: "https://oauth2.googleapis.com/token".to_string(),
redirect_uris: vec!["http://127.0.0.1:8080/".to_string()],
client_email: None,
client_x509_cert_url: None,
project_id: None,
..Default::default()
};
let secret = yup_oauth2::read_application_secret(secret_path)
.await
.map_err(|e| ApiError::Auth(format!("Failed to read secret file: {}", e)))?;
let authenticator = InstalledFlowAuthenticator::builder(
secret,