From 90342dd493afb72d5bd960c46ea151bfb874f0aa Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 8 Aug 2025 18:19:27 -0400 Subject: [PATCH] tsk-51: Saving changes Adding more functions to access and validate the token type --- src/callers/login.rs | 10 +++++++++- src/repo/mod.rs | 3 +++ src/token_stuff/mod.rs | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 6f94daf..c171218 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -165,7 +165,15 @@ pub mod endpoint { // * Check token type // - For right now, just worry about service tokens // * Create a new token with a longer expiration - (axum::http::StatusCode::OK, axum::Json(response)) + let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap(); + + if token_stuff::is_token_type_valid(&token_type) { + // let (token_literal, dur) = token_stuff::create_service_refresh_token(&key, ) + (axum::http::StatusCode::OK, axum::Json(response)) + } else { + response.message = String::from("Invalid token type"); + (axum::http::StatusCode::NOT_FOUND, axum::Json(response)) + } } else { response.message = String::from("Could not verify token"); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) diff --git a/src/repo/mod.rs b/src/repo/mod.rs index db62bb4..e959406 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -223,4 +223,7 @@ pub mod service { Err(err) => Err(err), } } + + // TODO: Write a function to get a passphrase record with an id + // pub async fn get_passphrase(pool: &) } diff --git a/src/token_stuff/mod.rs b/src/token_stuff/mod.rs index 0a94595..f14848b 100644 --- a/src/token_stuff/mod.rs +++ b/src/token_stuff/mod.rs @@ -69,6 +69,14 @@ pub fn extract_id_from_token(key: &String, token: &String) -> Result Result { + Ok(String::new()) +} + +pub fn is_token_type_valid(token_type: &String) -> bool { + false +} + fn get_payload( key: &String, token: &String,