tsk-51: Refresh token endpoint #54

Merged
phoenix merged 16 commits from tsk-51 into devel 2025-08-11 22:15:18 +00:00
4 changed files with 1 additions and 49 deletions
Showing only changes of commit 3517bbf015 - Show all commits

View File

@@ -154,7 +154,6 @@ pub mod endpoint {
} }
} }
// TODO: Add endpoint to get a refresh token
pub async fn refresh_token( pub async fn refresh_token(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::Json(payload): axum::Json<request::refresh_token::Request>, 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; let key = icarus_envy::environment::get_secret_key().await;
if token_stuff::verify_token(&key, &payload.access_token) { 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(); let token_type = token_stuff::get_token_type(&key, &payload.access_token).unwrap();
if token_stuff::is_token_type_valid(&token_type) { 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 // Get passphrase record with id
// 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) => match repo::service::get_passphrase(&pool, &id).await { Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
Ok((returned_id, _, _)) => { Ok((returned_id, _, _)) => {

View File

@@ -465,38 +465,6 @@ mod tests {
assert!(false, "Error: {err:?}"); 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; let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
} }

View File

@@ -224,7 +224,6 @@ pub mod service {
} }
} }
// TODO: Write a function to get a passphrase record with an id
pub async fn get_passphrase( pub async fn get_passphrase(
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
id: &uuid::Uuid, id: &uuid::Uuid,

View File

@@ -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"))) Err(std::io::Error::other(String::from("Invalid subject")))
} }
} }
None => Err(std::io::Error::other(String::from("Invalid payload"))), // } 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")),
*/
}, },
Err(err) => Err(std::io::Error::other(err.to_string())), 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 { pub fn is_token_type_valid(token_type: &String) -> bool {
token_type == SERVICE_TOKEN_TYPE token_type == SERVICE_TOKEN_TYPE
// false
} }
fn get_payload( fn get_payload(