Add API key auth

https://feedback.yaak.app/p/header-as-auth-option
This commit is contained in:
Gregory Schier
2025-07-20 09:15:03 -07:00
parent 947926ca34
commit 144faad31f
12 changed files with 153 additions and 52 deletions

View File

@@ -69,7 +69,7 @@ pub(crate) async fn build_metadata<R: Runtime>(
let auth = request.authentication.clone();
let plugin_req = CallHttpAuthenticationRequest {
context_id: format!("{:x}", md5::compute(authentication_context_id)),
values: serde_json::from_value(serde_json::to_value(&auth).unwrap()).unwrap(),
values: serde_json::from_value(serde_json::to_value(&auth)?)?,
method: "POST".to_string(),
url: request.url.clone(),
headers: metadata
@@ -83,7 +83,7 @@ pub(crate) async fn build_metadata<R: Runtime>(
let plugin_result = plugin_manager
.call_http_authentication(&window, &authentication_type, plugin_req)
.await?;
for header in plugin_result.set_headers {
for header in plugin_result.set_headers.unwrap_or_default() {
metadata.insert(header.name, header.value);
}
}

View File

@@ -452,10 +452,7 @@ pub async fn send_http_request<R: Runtime>(
Some(authentication_type) => {
let req = CallHttpAuthenticationRequest {
context_id: format!("{:x}", md5::compute(auth_context_id)),
values: serde_json::from_value(
serde_json::to_value(&request.authentication).unwrap(),
)
.unwrap(),
values: serde_json::from_value(serde_json::to_value(&request.authentication)?)?,
url: sendable_req.url().to_string(),
method: sendable_req.method().to_string(),
headers: sendable_req
@@ -482,11 +479,19 @@ pub async fn send_http_request<R: Runtime>(
};
let headers = sendable_req.headers_mut();
for header in plugin_result.set_headers {
headers.insert(
HeaderName::from_str(&header.name).unwrap(),
HeaderValue::from_str(&header.value).unwrap(),
);
for header in plugin_result.set_headers.unwrap_or_default() {
match (HeaderName::from_str(&header.name), HeaderValue::from_str(&header.value)) {
(Ok(name), Ok(value)) => {
headers.insert(name, value);
}
_ => continue,
};
}
let mut query_pairs = sendable_req.url_mut().query_pairs_mut();
for p in plugin_result.set_query_parameters.unwrap_or_default() {
println!("Adding query parameter: {:?}", p);
query_pairs.append_pair(&p.name, &p.value);
}
}
}