JWT auth plugin and necessary updates

This commit is contained in:
Gregory Schier
2025-01-17 08:02:55 -08:00
parent bd322162c8
commit 07ff709429
24 changed files with 327 additions and 104 deletions

View File

@@ -369,14 +369,8 @@ pub async fn send_http_request<R: Runtime>(
};
// Apply authentication
// Map legacy auth name values from before they were plugins
let auth_plugin_name = match request.authentication_type.clone() {
Some(s) if s == "basic" => Some("@yaakapp/auth-basic".to_string()),
Some(s) if s == "bearer" => Some("@yaakapp/auth-bearer".to_string()),
_ => request.authentication_type.to_owned(),
};
if let Some(plugin_name) = auth_plugin_name {
if let Some(auth_name) = request.authentication_type.to_owned() {
let req = CallHttpAuthenticationRequest {
config: serde_json::to_value(&request.authentication)
.unwrap()
@@ -395,13 +389,13 @@ pub async fn send_http_request<R: Runtime>(
.collect(),
};
let plugin_result =
match plugin_manager.call_http_authentication(window, &plugin_name, req).await {
match plugin_manager.call_http_authentication(window, &auth_name, req).await {
Ok(r) => r,
Err(e) => {
return Ok(response_err(&*response.lock().await, e.to_string(), window).await);
}
};
{
let url = sendable_req.url_mut();
*url = Url::parse(&plugin_result.url).unwrap();

View File

@@ -235,19 +235,10 @@ async fn cmd_grpc_go<R: Runtime>(
metadata.insert(h.name, h.value);
}
// Map legacy auth name values from before they were plugins
let auth_plugin_name = match req.authentication_type.clone() {
Some(s) if s == "basic" => Some("@yaakapp/auth-basic".to_string()),
Some(s) if s == "bearer" => Some("@yaakapp/auth-bearer".to_string()),
_ => req.authentication_type.to_owned(),
};
if let Some(plugin_name) = auth_plugin_name {
if let Some(auth_name) = req.authentication_type.clone() {
let auth = req.authentication.clone();
let plugin_req = CallHttpAuthenticationRequest {
config: serde_json::to_value(&req.authentication)
.unwrap()
.as_object()
.unwrap()
.to_owned(),
config: serde_json::to_value(&auth).unwrap().as_object().unwrap().to_owned(),
method: "POST".to_string(),
url: req.url.clone(),
headers: metadata
@@ -259,7 +250,7 @@ async fn cmd_grpc_go<R: Runtime>(
.collect(),
};
let plugin_result = plugin_manager
.call_http_authentication(&window, &plugin_name, plugin_req)
.call_http_authentication(&window, &auth_name, plugin_req)
.await
.map_err(|e| e.to_string())?;
@@ -980,7 +971,9 @@ async fn cmd_get_http_authentication<R: Runtime>(
window: WebviewWindow<R>,
plugin_manager: State<'_, PluginManager>,
) -> Result<Vec<GetHttpAuthenticationResponse>, String> {
plugin_manager.get_http_authentication(&window).await.map_err(|e| e.to_string())
let results =
plugin_manager.get_http_authentication(&window).await.map_err(|e| e.to_string())?;
Ok(results.into_iter().map(|(_, a)| a).collect())
}
#[tauri::command]

View File

@@ -46,9 +46,10 @@ impl TemplateCallback for PluginTemplateCallback {
let mut args_with_defaults = args.clone();
// Fill in default values for all args
for a_def in function.args {
let base = match a_def {
for arg in function.args {
let base = match arg {
FormInput::Text(a) => a.base,
FormInput::Editor(a) => a.base,
FormInput::Select(a) => a.base,
FormInput::Checkbox(a) => a.base,
FormInput::File(a) => a.base,