tsk-51: Endpoint is now available
This commit is contained in:
@@ -58,6 +58,10 @@ pub mod endpoint {
|
||||
use super::request;
|
||||
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>) {
|
||||
(
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -129,7 +133,7 @@ pub mod endpoint {
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
id,
|
||||
username: String::from("service"),
|
||||
username: String::from(SERVICE_USERNAME),
|
||||
token: token_literal,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
expiration: duration,
|
||||
@@ -172,38 +176,45 @@ pub mod endpoint {
|
||||
// Get passphrase record with id
|
||||
// match repo::service::get_passphrase
|
||||
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||
Ok(id) => {
|
||||
match repo::service::get_passphrase(&pool, &id).await {
|
||||
Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
|
||||
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)) => {
|
||||
let login_result =
|
||||
icarus_models::login_result::LoginResult {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
id: returned_id,
|
||||
token: access_token,
|
||||
expiration: exp_dur,
|
||||
token_type: String::from(
|
||||
icarus_models::token::TOKEN_TYPE,
|
||||
),
|
||||
username: String::from("service"),
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
username: String::from(SERVICE_USERNAME),
|
||||
};
|
||||
}
|
||||
Err(err) => {}
|
||||
}
|
||||
/*
|
||||
*/
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(login_result);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
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::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 {
|
||||
|
@@ -45,6 +45,10 @@ mod init {
|
||||
callers::endpoints::SERVICE_LOGIN,
|
||||
post(callers::login::endpoint::service_login),
|
||||
)
|
||||
.route(
|
||||
callers::endpoints::REFRESH_TOKEN,
|
||||
post(callers::login::endpoint::refresh_token),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn app() -> Router {
|
||||
|
Reference in New Issue
Block a user