Misc fixes

This commit is contained in:
lewis
2025-12-26 18:10:54 +02:00
parent ff59c29147
commit 77a67f3554
13 changed files with 51 additions and 73 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ pub async fn verify_migration_email(
identifier: input.email,
};
let result = super::verify_token::verify_token_internal(&state, None, token_input).await?;
let result = super::verify_token::verify_token_internal(&state, token_input).await?;
Ok(Json(VerifyMigrationEmailOutput {
success: result.success,
+2 -46
View File
@@ -1,7 +1,7 @@
use axum::{
Json,
extract::State,
http::{HeaderMap, StatusCode},
http::StatusCode,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -30,15 +30,13 @@ pub struct VerifyTokenOutput {
pub async fn verify_token(
State(state): State<AppState>,
headers: HeaderMap,
Json(input): Json<VerifyTokenInput>,
) -> Result<Json<VerifyTokenOutput>, (StatusCode, Json<serde_json::Value>)> {
verify_token_internal(&state, Some(&headers), input).await
verify_token_internal(&state, input).await
}
pub async fn verify_token_internal(
state: &AppState,
headers: Option<&HeaderMap>,
input: VerifyTokenInput,
) -> Result<Json<VerifyTokenOutput>, (StatusCode, Json<serde_json::Value>)> {
let normalized_token = normalize_token_input(&input.token);
@@ -95,15 +93,6 @@ pub async fn verify_token_internal(
.await
}
VerificationPurpose::ChannelUpdate => {
let auth_did = extract_and_validate_auth(state, headers).await?;
if auth_did != token_data.did {
return Err((
StatusCode::BAD_REQUEST,
Json(
json!({ "error": "InvalidToken", "message": "Token does not match authenticated account" }),
),
));
}
handle_channel_update(state, &token_data.did, &token_data.channel, &identifier).await
}
VerificationPurpose::Signup => {
@@ -113,39 +102,6 @@ pub async fn verify_token_internal(
}
}
async fn extract_and_validate_auth(
state: &AppState,
headers: Option<&HeaderMap>,
) -> Result<String, (StatusCode, Json<serde_json::Value>)> {
let headers = headers.ok_or_else(|| {
(
StatusCode::UNAUTHORIZED,
Json(json!({ "error": "AuthenticationRequired", "message": "Authentication required for this verification" })),
)
})?;
let token = crate::auth::extract_bearer_token_from_header(
headers.get("Authorization").and_then(|h| h.to_str().ok()),
)
.ok_or_else(|| {
(
StatusCode::UNAUTHORIZED,
Json(json!({ "error": "AuthenticationRequired", "message": "Authentication required for this verification" })),
)
})?;
let user = crate::auth::validate_bearer_token(&state.db, &token)
.await
.map_err(|_| {
(
StatusCode::UNAUTHORIZED,
Json(json!({ "error": "AuthenticationFailed", "message": "Invalid authentication token" })),
)
})?;
Ok(user.did)
}
async fn handle_migration_verification(
state: &AppState,
did: &str,
+1 -3
View File
@@ -2,7 +2,6 @@ use crate::state::AppState;
use axum::{
Json,
extract::State,
http::HeaderMap,
response::{IntoResponse, Response},
};
use serde::Deserialize;
@@ -18,7 +17,6 @@ pub struct ConfirmChannelVerificationInput {
pub async fn confirm_channel_verification(
State(state): State<AppState>,
headers: HeaderMap,
Json(input): Json<ConfirmChannelVerificationInput>,
) -> Response {
let token_input = crate::api::server::VerifyTokenInput {
@@ -26,7 +24,7 @@ pub async fn confirm_channel_verification(
identifier: input.identifier,
};
match crate::api::server::verify_token_internal(&state, Some(&headers), token_input).await {
match crate::api::server::verify_token_internal(&state, token_input).await {
Ok(output) => Json(json!({"success": output.success})).into_response(),
Err((status, err_json)) => (status, err_json).into_response(),
}