tsk-51: Code cleanup
This commit is contained in:
@@ -154,7 +154,6 @@ 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>,
|
||||
@@ -166,15 +165,10 @@ pub mod endpoint {
|
||||
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
|
||||
let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap();
|
||||
|
||||
if token_stuff::is_token_type_valid(&token_type) {
|
||||
// let (token_literal, dur) = token_stuff::create_service_refresh_token(&key, )
|
||||
// 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((returned_id, _, _)) => {
|
||||
|
32
src/main.rs
32
src/main.rs
@@ -465,38 +465,6 @@ mod tests {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
/*
|
||||
let passphrase =
|
||||
String::from("iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH");
|
||||
let payload = serde_json::json!({
|
||||
"passphrase": passphrase
|
||||
});
|
||||
|
||||
match app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method(axum::http::Method::POST)
|
||||
.uri(callers::endpoints::SERVICE_LOGIN)
|
||||
.header(axum::http::header::CONTENT_TYPE, "application/json")
|
||||
.body(Body::from(payload.to_string()))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
assert_eq!(StatusCode::OK, response.status(), "Status is not right");
|
||||
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let parsed_body: callers::login::response::service_login::Response =
|
||||
serde_json::from_slice(&body).unwrap();
|
||||
let _login_result = &parsed_body.data[0];
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
|
@@ -224,7 +224,6 @@ pub mod service {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Write a function to get a passphrase record with an id
|
||||
pub async fn get_passphrase(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
|
@@ -99,15 +99,7 @@ pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::E
|
||||
Err(std::io::Error::other(String::from("Invalid subject")))
|
||||
}
|
||||
}
|
||||
None => Err(std::io::Error::other(String::from("Invalid payload"))), // }
|
||||
/*
|
||||
match payload.claim("id") {
|
||||
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
||||
Ok(extracted) => Ok(extracted),
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
None => Err(std::io::Error::other("No claim found")),
|
||||
*/
|
||||
None => Err(std::io::Error::other(String::from("Invalid payload"))),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
@@ -115,7 +107,6 @@ pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::E
|
||||
|
||||
pub fn is_token_type_valid(token_type: &String) -> bool {
|
||||
token_type == SERVICE_TOKEN_TYPE
|
||||
// false
|
||||
}
|
||||
|
||||
fn get_payload(
|
||||
|
Reference in New Issue
Block a user