Update dependencies (#19)
Rust Build / Rustfmt (push) Successful in 50s
Rust Build / Check (push) Successful in 1m7s
Rust Build / Test Suite (push) Failing after 2m2s
Rust Build / Clippy (push) Successful in 1m27s
Rust Build / build (push) Successful in 1m30s

Reviewed-on: phoenix/textsender_auth#19
This commit was merged in pull request #19.
This commit is contained in:
2026-07-04 20:00:46 -04:00
parent 9dba08f179
commit 21bfaf7657
7 changed files with 81 additions and 681 deletions
Generated
+54 -645
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "textsender_auth" name = "textsender_auth"
version = "0.2.1" version = "0.2.2"
edition = "2024" edition = "2024"
rust-version = "1.96" rust-version = "1.96"
@@ -10,15 +10,15 @@ serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.150" } serde_json = { version = "1.0.150" }
tokio = { version = "1.52.3", features = ["rt-multi-thread"] } tokio = { version = "1.52.3", features = ["rt-multi-thread"] }
tracing-subscriber = { version = "0.3.23" } tracing-subscriber = { version = "0.3.23" }
tower-http = { version = "0.6.11", features = ["cors"] } tower-http = { version = "0.7.0", features = ["cors"] }
sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] } sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
uuid = { version = "1.23.3", features = ["v4", "serde"] } uuid = { version = "1.23.3", features = ["v4", "serde"] }
argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version argon2 = { version = "0.5.3", features = ["std"] } # Use the latest 0.5.x version
time = { version = "0.3.49", features = ["macros", "serde"] } time = { version = "0.3.53", features = ["macros", "serde"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa = { version = "5.5.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.4.10", features = ["config", "user"] } textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.5.0", features = ["config", "user"] }
[dev-dependencies] [dev-dependencies]
tower = { version = "0.5.3", features = ["full"] } tower = { version = "0.5.3", features = ["full"] }
+5 -9
View File
@@ -192,9 +192,8 @@ pub async fn user_login(
Ok(matches) => { Ok(matches) => {
if matches { if matches {
// Create token // Create token
let key = textsender_models::envy::environment::get_secret_key() let key =
.await textsender_models::envy::environment::get_secret_key().value;
.value;
let cst = token_stuff::create_token(&key, &user.id).unwrap(); let cst = token_stuff::create_token(&key, &user.id).unwrap();
if token_stuff::verify_token(&key, &cst.access_token) { if token_stuff::verify_token(&key, &cst.access_token) {
@@ -332,9 +331,8 @@ pub async fn service_user_login(
if matches { if matches {
// Create token // Create token
println!("Creating token"); println!("Creating token");
let key = textsender_models::envy::environment::get_secret_key() let key =
.await textsender_models::envy::environment::get_secret_key().value;
.value;
let cst = let cst =
token_stuff::create_token(&key, &service_user.id).unwrap(); token_stuff::create_token(&key, &service_user.id).unwrap();
@@ -439,9 +437,7 @@ pub async fn refresh_token(
}), }),
) )
} else { } else {
let key = textsender_models::envy::environment::get_secret_key() let key = textsender_models::envy::environment::get_secret_key().value;
.await
.value;
if token_stuff::verify_token(&key, &payload.access_token) { if token_stuff::verify_token(&key, &payload.access_token) {
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) => {
+1 -1
View File
@@ -183,7 +183,7 @@ pub async fn register_user(
/// Checks to see if registration is enabled /// Checks to see if registration is enabled
async fn is_registration_enabled() -> Result<bool, std::io::Error> { async fn is_registration_enabled() -> Result<bool, std::io::Error> {
let key = String::from("ENABLE_REGISTRATION"); let key = String::from("ENABLE_REGISTRATION");
let var = textsender_models::envy::environment::get_env(&key).await; let var = textsender_models::envy::environment::get_env(&key);
let parsed_value = var.value.to_uppercase(); let parsed_value = var.value.to_uppercase();
if parsed_value == "TRUE" { if parsed_value == "TRUE" {
+1 -3
View File
@@ -1,9 +1,7 @@
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> { pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
let database_url = textsender_models::envy::environment::get_db_url() let database_url = textsender_models::envy::environment::get_db_url().value;
.await
.value;
println!("Database url: {database_url}"); println!("Database url: {database_url}");
PgPoolOptions::new() PgPoolOptions::new()
+1 -1
View File
@@ -58,7 +58,7 @@ pub mod init {
match std::env::var(textsender_models::envy::keys::APP_ENV).as_deref() { match std::env::var(textsender_models::envy::keys::APP_ENV).as_deref() {
Ok("production") => { Ok("production") => {
let allowed_origins_env = let allowed_origins_env =
textsender_models::envy::environment::get_allowed_origins().await; textsender_models::envy::environment::get_allowed_origins();
match textsender_models::envy::utility::delimitize(&allowed_origins_env) { match textsender_models::envy::utility::delimitize(&allowed_origins_env) {
Ok(alwd) => { Ok(alwd) => {
let allowed_origins: Vec<axum::http::HeaderValue> = alwd let allowed_origins: Vec<axum::http::HeaderValue> = alwd
+15 -18
View File
@@ -17,7 +17,7 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
} }
pub fn create_token( pub fn create_token(
provided_key: &String, provided_key: &str,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
@@ -26,11 +26,11 @@ pub fn create_token(
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
user_id: *id, user_id: *id,
}; };
textsender_models::token::create_token(provided_key, &resource, time::Duration::hours(4)) textsender_models::token::create_token(provided_key, resource, time::Duration::hours(4))
} }
pub fn create_service_token( pub fn create_service_token(
provided: &String, provided: &str,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
@@ -39,11 +39,11 @@ pub fn create_service_token(
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
user_id: *id, user_id: *id,
}; };
textsender_models::token::create_token(provided, &resource, time::Duration::hours(1)) textsender_models::token::create_token(provided, resource, time::Duration::hours(1))
} }
pub fn create_service_refresh_token( pub fn create_service_refresh_token(
key: &String, key: &str,
id: &uuid::Uuid, id: &uuid::Uuid,
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> { ) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
let resource = textsender_models::token::TokenResource { let resource = textsender_models::token::TokenResource {
@@ -52,10 +52,10 @@ pub fn create_service_refresh_token(
audiences: vec![String::from(AUDIENCE)], audiences: vec![String::from(AUDIENCE)],
user_id: *id, user_id: *id,
}; };
textsender_models::token::create_token(key, &resource, time::Duration::hours(4)) textsender_models::token::create_token(key, resource, time::Duration::hours(4))
} }
pub fn verify_token(key: &String, token: &String) -> bool { pub fn verify_token(key: &str, token: &str) -> bool {
match get_payload(key, token) { match get_payload(key, token) {
Ok((payload, _header)) => match payload.subject() { Ok((payload, _header)) => match payload.subject() {
Some(_sub) => true, Some(_sub) => true,
@@ -65,7 +65,7 @@ pub fn verify_token(key: &String, token: &String) -> bool {
} }
} }
pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> { pub fn extract_id_from_token(key: &str, token: &str) -> Result<uuid::Uuid, std::io::Error> {
match get_payload(key, token) { match get_payload(key, token) {
Ok((payload, _header)) => match payload.claim("user_id") { Ok((payload, _header)) => match payload.claim("user_id") {
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) { Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
@@ -83,7 +83,7 @@ pub const APP_SUBJECT: &str = "Something random";
pub const SERVICE_TOKEN_TYPE: &str = "Textsender_Service"; pub const SERVICE_TOKEN_TYPE: &str = "Textsender_Service";
pub const SERVICE_SUBJECT: &str = "Service random"; pub const SERVICE_SUBJECT: &str = "Service random";
pub fn get_token_type(key: &String, token: &String) -> Result<String, std::io::Error> { pub fn get_token_type(key: &str, token: &str) -> Result<String, std::io::Error> {
match get_payload(key, token) { match get_payload(key, token) {
Ok((payload, _header)) => match payload.subject() { Ok((payload, _header)) => match payload.subject() {
Some(subject) => { Some(subject) => {
@@ -101,13 +101,13 @@ 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: &str) -> bool {
token_type == SERVICE_TOKEN_TYPE token_type == SERVICE_TOKEN_TYPE
} }
fn get_payload( fn get_payload(
key: &String, key: &str,
token: &String, token: &str,
) -> Result<(josekit::jwt::JwtPayload, josekit::jws::JwsHeader), josekit::JoseError> { ) -> Result<(josekit::jwt::JwtPayload, josekit::jws::JwsHeader), josekit::JoseError> {
let ver = Hs256.verifier_from_bytes(key.as_bytes()).unwrap(); let ver = Hs256.verifier_from_bytes(key.as_bytes()).unwrap();
jwt::decode_with_verifier(token, &ver) jwt::decode_with_verifier(token, &ver)
@@ -119,14 +119,11 @@ mod tests {
#[test] #[test]
fn test_tokenize() { fn test_tokenize() {
let rt = tokio::runtime::Runtime::new().unwrap(); let special_key = textsender_models::envy::environment::get_secret_key();
let special_key = rt
.block_on(textsender_models::envy::environment::get_secret_key())
.value;
let id = uuid::Uuid::new_v4(); let id = uuid::Uuid::new_v4();
match create_token(&special_key, &id) { match create_token(&special_key.value, &id) {
Ok(cst) => { Ok(cst) => {
let result = verify_token(&special_key, &cst.access_token); let result = verify_token(&special_key.value, &cst.access_token);
assert!(result, "Token not verified"); assert!(result, "Token not verified");
} }
Err(err) => { Err(err) => {