tsk-51: Refresh token endpoint #54
@@ -13,6 +13,13 @@ pub mod request {
|
|||||||
pub passphrase: String,
|
pub passphrase: String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod refresh_token {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Request {
|
||||||
|
pub access_token: String,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
@@ -31,6 +38,14 @@ pub mod response {
|
|||||||
pub data: Vec<icarus_models::login_result::LoginResult>,
|
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 {
|
pub mod endpoint {
|
||||||
@@ -134,4 +149,18 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add endpoint to get a refresh token
|
// 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user