tsk-51: Endpoint is now available

This commit is contained in:
2025-08-11 17:22:30 -04:00
parent 2e4c289998
commit 17fd2de892
2 changed files with 43 additions and 28 deletions

View File

@@ -58,6 +58,10 @@ pub mod endpoint {
use super::request; use super::request;
use super::response; use super::response;
// TODO: At some point, get the username from the DB
// Name of service username when returning a login result
pub const SERVICE_USERNAME: &str = "service";
async fn not_found(message: &str) -> (StatusCode, Json<response::Response>) { async fn not_found(message: &str) -> (StatusCode, Json<response::Response>) {
( (
StatusCode::NOT_FOUND, StatusCode::NOT_FOUND,
@@ -129,7 +133,7 @@ pub mod endpoint {
if token_stuff::verify_token(&key, &token_literal) { if token_stuff::verify_token(&key, &token_literal) {
let login_result = icarus_models::login_result::LoginResult { let login_result = icarus_models::login_result::LoginResult {
id, id,
username: String::from("service"), username: String::from(SERVICE_USERNAME),
token: token_literal, token: token_literal,
token_type: String::from(icarus_models::token::TOKEN_TYPE), token_type: String::from(icarus_models::token::TOKEN_TYPE),
expiration: duration, expiration: duration,
@@ -172,38 +176,45 @@ pub mod endpoint {
// Get passphrase record with id // Get passphrase record with id
// match repo::service::get_passphrase // match repo::service::get_passphrase
match token_stuff::extract_id_from_token(&key, &payload.access_token) { match token_stuff::extract_id_from_token(&key, &payload.access_token) {
Ok(id) => { Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
match repo::service::get_passphrase(&pool, &id).await {
Ok((returned_id, _, _)) => { Ok((returned_id, _, _)) => {
match token_stuff::create_service_refresh_token(&key, &returned_id) match token_stuff::create_service_refresh_token(&key, &returned_id) {
{
Ok((access_token, exp_dur)) => { Ok((access_token, exp_dur)) => {
let login_result = let login_result = icarus_models::login_result::LoginResult {
icarus_models::login_result::LoginResult {
id: returned_id, id: returned_id,
token: access_token, token: access_token,
expiration: exp_dur, expiration: exp_dur,
token_type: String::from( token_type: String::from(icarus_models::token::TOKEN_TYPE),
icarus_models::token::TOKEN_TYPE, username: String::from(SERVICE_USERNAME),
),
username: String::from("service"),
}; };
} response.message = String::from("Successful");
Err(err) => {} response.data.push(login_result);
}
/*
*/
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); response.message = err.to_string();
(axum::http::StatusCode::OK, axum::Json(response)) (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
} }
} }
} }
Err(err) => { Err(err) => {
response.message = err.to_string(); response.message = err.to_string();
(axum::http::StatusCode::OK, axum::Json(response)) (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
},
Err(err) => {
response.message = err.to_string();
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
} }
} }
} else { } else {

View File

@@ -45,6 +45,10 @@ mod init {
callers::endpoints::SERVICE_LOGIN, callers::endpoints::SERVICE_LOGIN,
post(callers::login::endpoint::service_login), post(callers::login::endpoint::service_login),
) )
.route(
callers::endpoints::REFRESH_TOKEN,
post(callers::login::endpoint::refresh_token),
)
} }
pub async fn app() -> Router { pub async fn app() -> Router {