From 6333444b04b53658b4e9947a007f81f3365c1586 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 5 Aug 2025 18:49:20 -0400 Subject: [PATCH] tsk-51: Added endpoint to obtain refresh token --- src/callers/login.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/callers/login.rs b/src/callers/login.rs index 33e0d52..b1c79ab 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -13,6 +13,13 @@ pub mod request { pub passphrase: String, } } + + pub mod refresh_token { + #[derive(Debug, serde::Deserialize, serde::Serialize)] + pub struct Request { + pub access_token: String, + } + } } pub mod response { @@ -31,6 +38,14 @@ pub mod response { pub data: Vec, } } + + pub mod refresh_token { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } } pub mod endpoint { @@ -134,4 +149,18 @@ pub mod endpoint { } // TODO: Add endpoint to get a refresh token + pub async fn refresh_token(axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json) -> (axum::http::StatusCode, axum::Json) { + let mut response = response::refresh_token::Response::default(); + let key = icarus_envy::environment::get_secret_key().await; + + if token_stuff::verify_token(&key, &payload.access_token) { + // * 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)) + } else { + response.message = String::from("Could not verify token"); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } }