tsk-51: Refresh token endpoint #54
@@ -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)) => {
|
||||||
{
|
let login_result = icarus_models::login_result::LoginResult {
|
||||||
Ok((access_token, exp_dur)) => {
|
id: returned_id,
|
||||||
let login_result =
|
token: access_token,
|
||||||
icarus_models::login_result::LoginResult {
|
expiration: exp_dur,
|
||||||
id: returned_id,
|
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||||
token: access_token,
|
username: String::from(SERVICE_USERNAME),
|
||||||
expiration: exp_dur,
|
};
|
||||||
token_type: String::from(
|
response.message = String::from("Successful");
|
||||||
icarus_models::token::TOKEN_TYPE,
|
response.data.push(login_result);
|
||||||
),
|
|
||||||
username: String::from("service"),
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
};
|
}
|
||||||
}
|
Err(err) => {
|
||||||
Err(err) => {}
|
response.message = err.to_string();
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
*/
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(
|
||||||
|
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),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -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 {
|
||||||
|
Reference in New Issue
Block a user