Skip to content

Commit

Permalink
chore(friendshipper): move oidc auth + refresh logic into the backend"
Browse files Browse the repository at this point in the history
  • Loading branch information
rudoi committed Dec 16, 2024
1 parent 9cecf72 commit 9588bb5
Show file tree
Hide file tree
Showing 27 changed files with 1,295 additions and 683 deletions.
600 changes: 562 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ opentelemetry = "0.21.0"
opentelemetry-otlp = { version = "0.14.0", features = ["http-proto", "reqwest-client"] }
opentelemetry_sdk = { version = "0.21.1", features = ["rt-tokio"] }
parking_lot = "0.12.1"
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
regex = "1.9.3"
retry = "2.0.0"
self-replace = "1.3.5"
Expand Down
52 changes: 31 additions & 21 deletions birdie/src-tauri/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ethos_core::types::commits::Commit;
use ethos_core::types::locks::VerifyLocksResponse;
use ethos_core::types::repo::{CommitFileInfo, LockRequest, PushRequest, RepoStatus};

use crate::State;
use crate::TauriState;

// Add this function at the top of the file, after imports
async fn create_tauri_error(res: reqwest::Response) -> TauriError {
Expand All @@ -24,7 +24,7 @@ async fn create_tauri_error(res: reqwest::Response) -> TauriError {
}

#[tauri::command]
pub async fn get_config(state: tauri::State<'_, State>) -> Result<BirdieConfig, TauriError> {
pub async fn get_config(state: tauri::State<'_, TauriState>) -> Result<BirdieConfig, TauriError> {
let res = state
.client
.get(format!("{}/config", state.server_url))
Expand All @@ -40,7 +40,7 @@ pub async fn get_config(state: tauri::State<'_, State>) -> Result<BirdieConfig,

#[tauri::command]
pub async fn update_config(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
config: BirdieConfig,
) -> Result<BirdieConfig, TauriError> {
let res = state
Expand All @@ -59,7 +59,7 @@ pub async fn update_config(

#[tauri::command]
pub async fn show_commit_files(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
commit: String,
) -> Result<Vec<CommitFileInfo>, TauriError> {
let res = state
Expand All @@ -77,7 +77,7 @@ pub async fn show_commit_files(

#[tauri::command]
pub async fn get_file_history(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
file: String,
) -> Result<Vec<Commit>, TauriError> {
// url encode the file
Expand All @@ -101,7 +101,9 @@ pub async fn get_file_history(

// Repo
#[tauri::command]
pub async fn get_repo_status(state: tauri::State<'_, State>) -> Result<RepoStatus, TauriError> {
pub async fn get_repo_status(
state: tauri::State<'_, TauriState>,
) -> Result<RepoStatus, TauriError> {
let res = state
.client
.get(format!("{}/repo/status", state.server_url))
Expand All @@ -115,7 +117,10 @@ pub async fn get_repo_status(state: tauri::State<'_, State>) -> Result<RepoStatu
}

#[tauri::command]
pub async fn submit(state: tauri::State<'_, State>, req: PushRequest) -> Result<(), TauriError> {
pub async fn submit(
state: tauri::State<'_, TauriState>,
req: PushRequest,
) -> Result<(), TauriError> {
let res = state
.client
.post(format!("{}/repo/push", state.server_url))
Expand All @@ -135,7 +140,7 @@ pub async fn submit(state: tauri::State<'_, State>, req: PushRequest) -> Result<
// LFS
#[tauri::command]
pub async fn download_lfs_files(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
files: Vec<String>,
include_wip: bool,
) -> Result<(), TauriError> {
Expand All @@ -155,7 +160,7 @@ pub async fn download_lfs_files(

#[tauri::command]
pub async fn lock_files(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
paths: Vec<String>,
) -> Result<(), TauriError> {
let res = state
Expand All @@ -177,7 +182,7 @@ pub async fn lock_files(

#[tauri::command]
pub async fn unlock_files(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
paths: Vec<String>,
force: bool,
) -> Result<(), TauriError> {
Expand All @@ -201,7 +206,7 @@ pub async fn unlock_files(
// Locks
#[tauri::command]
pub async fn verify_locks(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
) -> Result<VerifyLocksResponse, TauriError> {
let res = state
.client
Expand All @@ -218,7 +223,9 @@ pub async fn verify_locks(

// Git Config
#[tauri::command]
pub async fn get_fetch_include(state: tauri::State<'_, State>) -> Result<Vec<String>, TauriError> {
pub async fn get_fetch_include(
state: tauri::State<'_, TauriState>,
) -> Result<Vec<String>, TauriError> {
let res = state
.client
.get(format!("{}/repo/config/fetchinclude", state.server_url))
Expand All @@ -234,7 +241,7 @@ pub async fn get_fetch_include(state: tauri::State<'_, State>) -> Result<Vec<Str

#[tauri::command]
pub async fn del_fetch_include(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
files: Vec<String>,
) -> Result<(), TauriError> {
let res = state
Expand All @@ -253,7 +260,10 @@ pub async fn del_fetch_include(

// Birdie commands
#[tauri::command]
pub async fn get_file(state: tauri::State<'_, State>, path: String) -> Result<File, TauriError> {
pub async fn get_file(
state: tauri::State<'_, TauriState>,
path: String,
) -> Result<File, TauriError> {
let res = state
.client
.get(format!("{}/repo/file", state.server_url))
Expand All @@ -270,7 +280,7 @@ pub async fn get_file(state: tauri::State<'_, State>, path: String) -> Result<Fi

#[tauri::command]
pub async fn get_files(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
root: Option<String>,
) -> Result<Vec<File>, TauriError> {
let mut req = state.client.get(format!("{}/repo/files", state.server_url));
Expand All @@ -289,7 +299,7 @@ pub async fn get_files(
}

#[tauri::command]
pub async fn get_all_files(state: tauri::State<'_, State>) -> Result<Vec<String>, TauriError> {
pub async fn get_all_files(state: tauri::State<'_, TauriState>) -> Result<Vec<String>, TauriError> {
let res = state
.client
.get(format!("{}/repo/files/all", state.server_url))
Expand All @@ -306,7 +316,7 @@ pub async fn get_all_files(state: tauri::State<'_, State>) -> Result<Vec<String>
// Birdie metadata
#[tauri::command]
pub async fn get_directory_metadata(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
path: PathBuf,
) -> Result<DirectoryMetadata, TauriError> {
let res = state
Expand All @@ -327,7 +337,7 @@ pub async fn get_directory_metadata(
}
#[tauri::command]
pub async fn update_metadata_class(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
path: PathBuf,
directory_class: String,
) -> Result<(), TauriError> {
Expand All @@ -350,7 +360,7 @@ pub async fn update_metadata_class(

#[tauri::command]
pub async fn update_metadata(
state: tauri::State<'_, State>,
state: tauri::State<'_, TauriState>,
path: PathBuf,
metadata: DirectoryMetadata,
) -> Result<DirectoryMetadata, TauriError> {
Expand All @@ -369,7 +379,7 @@ pub async fn update_metadata(
}

#[tauri::command]
pub async fn sync_tools(state: tauri::State<'_, State>) -> Result<bool, TauriError> {
pub async fn sync_tools(state: tauri::State<'_, TauriState>) -> Result<bool, TauriError> {
let res = state
.client
.post(format!("{}/tools/sync", state.server_url))
Expand All @@ -387,7 +397,7 @@ pub async fn sync_tools(state: tauri::State<'_, State>) -> Result<bool, TauriErr
}

#[tauri::command]
pub async fn run_set_env(state: tauri::State<'_, State>) -> Result<(), TauriError> {
pub async fn run_set_env(state: tauri::State<'_, TauriState>) -> Result<(), TauriError> {
let res = state
.client
.post(format!("{}/tools/setenv", state.server_url))
Expand Down
5 changes: 3 additions & 2 deletions birdie/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tauri::{
use tracing::{error, info, warn};

use birdie::server::Server;
use ethos_core::tauri::State;
use ethos_core::tauri::TauriState;
use ethos_core::utils::logging;
use ethos_core::{clients, utils};

Expand Down Expand Up @@ -199,10 +199,11 @@ fn main() -> Result<(), CoreError> {
let (shutdown_tx, shutdown_rx) = tokio::sync::mpsc::channel::<()>(1);

tauri::Builder::default()
.manage(State {
.manage(TauriState {
server_url: server_url.clone(),
log_path: log_path.clone(),
client,
auth_state: None,
shutdown_tx,
})
.invoke_handler(tauri::generate_handler![
Expand Down
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ ureq = "2.6.2"
which = "4.4.0"
json-patch = "1.1.0"
ring = "0.17"
graphql_client = { version = "0.13.0", features = ["reqwest"] }
graphql_client = { git = "https://github.com/graphql-rust/graphql-client.git", rev = "9b91a7f7d4a21dbbeacf974bce63fe5e55620ca8", features = ["reqwest"] }
obws = "0.11.5"
futures = "0.3.29"
toml = "0.8.8"
async-trait = "0.1"
windows = { version = "0.56.0", features = ["Win32_Foundation", "Win32_Storage_FileSystem"] }
walkdir = "2.5.0"
octocrab = "0.39.0"
openidconnect = { git = "https://github.com/ramosbugs/openidconnect-rs.git", rev = "4.0.0-rc.1" }
bytes = "1.7.2"
tempfile = { workspace = true }
serde-xml-rs = "0.6.0"
Expand Down
12 changes: 12 additions & 0 deletions core/src/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
use serde::{Deserialize, Serialize};

pub mod sso;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OIDCTokens {
pub access_token: String,
pub id_token: String,

#[serde(skip_serializing_if = "Option::is_none")]
pub refresh_token: Option<String>,
}
2 changes: 1 addition & 1 deletion core/src/clients/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::middleware::nonce::{NONCE, NONCE_HEADER};
use anyhow::Result;
use http::header;
use reqwest::header;

pub fn new_reqwest_client() -> Result<reqwest::Client> {
let mut headers = header::HeaderMap::new();
Expand Down
5 changes: 5 additions & 0 deletions core/src/middleware/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pub async fn nonce(
next: Next,
value: &str,
) -> Result<Response, StatusCode> {
// if the URI is /auth/callback, we don't need to check the nonce
if request.uri().path() == "/auth/callback" {
return Ok(next.run(request).await);
}

if let Some(nonce) = headers.get(NONCE_HEADER) {
if nonce == value {
return Ok(next.run(request).await);
Expand Down
Loading

0 comments on commit 9588bb5

Please sign in to comment.