refactor: read client_secret.json from disk instead of env vars
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user