add request proxying and basic user auth

This commit is contained in:
sam 2024-01-19 16:44:18 +01:00
parent bfb0a1d1b0
commit 274c527ade
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
31 changed files with 541 additions and 36 deletions

View file

@ -19,6 +19,10 @@ pub enum FoxError {
MissingSignature,
#[error("invalid signature")]
InvalidSignature,
#[error("missing or invalid token")]
Unauthorized,
#[error("missing target user ID")]
MissingUser,
}
impl From<ToStrError> for FoxError {

View file

@ -40,10 +40,14 @@ fn plaintext_string(
.unwrap_or("".to_owned());
let raw_user_id = user_id.unwrap_or("".into());
format!(
let s = format!(
"{}:{}:{}:{}:{}",
raw_time, host, request_path, raw_content_length, raw_user_id
)
);
println!("{}", s);
s
}
pub fn format_date(time: DateTime<Utc>) -> String {

View file

@ -42,6 +42,7 @@ pub enum ErrorCode {
InvalidDate,
InvalidSignature,
MissingSignature,
Unauthorized,
}
impl From<sqlx::Error> for ApiError {
@ -121,6 +122,16 @@ impl From<FoxError> for ApiError {
code: ErrorCode::InvalidSignature,
message: "Invalid signature".into(),
},
FoxError::MissingUser => ApiError {
status: StatusCode::BAD_REQUEST,
code: ErrorCode::InvalidHeader,
message: "Missing user header".into(),
},
FoxError::Unauthorized => ApiError {
status: StatusCode::UNAUTHORIZED,
code: ErrorCode::Unauthorized,
message: "Missing or invalid token".into(),
}
}
}
}

View file

@ -1,7 +1,8 @@
pub mod error;
pub mod http;
pub mod s2s;
pub mod fed;
pub mod http;
pub mod model;
pub mod s2s;
pub use error::FoxError;
pub use fed::signature;

View file

@ -0,0 +1,10 @@
use serde::{Serialize, Deserialize};
use super::user::PartialUser;
#[derive(Serialize, Deserialize, Debug)]
pub struct Guild {
pub id: String,
pub name: String,
pub owner: PartialUser,
}

View file

@ -0,0 +1,6 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct CreateGuildParams {
pub name: String,
}

View file

@ -0,0 +1 @@
pub mod guild;

6
foxchat/src/model/mod.rs Normal file
View file

@ -0,0 +1,6 @@
pub mod guild;
pub mod user;
pub mod http;
pub use guild::Guild;
pub use user::User;

16
foxchat/src/model/user.rs Normal file
View file

@ -0,0 +1,16 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
pub id: String,
pub username: String,
pub instance: String,
pub avatar_url: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct PartialUser {
pub id: String,
pub username: String,
pub instance: String,
}