mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-28 05:12:33 +00:00
Co-authored-by: Steven Enamakel <31011319+senamakel@users.noreply.github.com> Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
20 lines
693 B
Rust
20 lines
693 B
Rust
//! Shared helpers for authenticated calls from the Tauri host to the local core RPC.
|
|
|
|
use reqwest::RequestBuilder;
|
|
|
|
const CORE_RPC_URL_ENV: &str = "OPENHUMAN_CORE_RPC_URL";
|
|
pub(crate) fn core_rpc_url_value() -> String {
|
|
std::env::var(CORE_RPC_URL_ENV).unwrap_or_else(|_| {
|
|
format!(
|
|
"http://127.0.0.1:{}/rpc",
|
|
crate::core_process::default_core_port()
|
|
)
|
|
})
|
|
}
|
|
|
|
pub(crate) fn apply_auth(builder: RequestBuilder) -> Result<RequestBuilder, String> {
|
|
let token = crate::core_process::current_rpc_token()
|
|
.ok_or_else(|| "core RPC token is not initialized".to_string())?;
|
|
Ok(builder.header("Authorization", format!("Bearer {token}")))
|
|
}
|