tsk-51: Added endpoint to obtain refresh token

This commit is contained in:
2025-08-05 18:49:20 -04:00
parent ce4e2c1712
commit 6333444b04

View File

@@ -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<icarus_models::login_result::LoginResult>,
}
}
pub mod refresh_token {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::login_result::LoginResult>,
}
}
}
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<sqlx::PgPool>, axum::Json(payload): axum::Json<request::refresh_token::Request>) -> (axum::http::StatusCode, axum::Json<response::refresh_token::Response>) {
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))
}
}
}