add request proxying and basic user auth
This commit is contained in:
parent
bfb0a1d1b0
commit
274c527ade
31 changed files with 541 additions and 36 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
10
foxchat/src/model/guild.rs
Normal file
10
foxchat/src/model/guild.rs
Normal 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,
|
||||
}
|
6
foxchat/src/model/http/guild.rs
Normal file
6
foxchat/src/model/http/guild.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CreateGuildParams {
|
||||
pub name: String,
|
||||
}
|
1
foxchat/src/model/http/mod.rs
Normal file
1
foxchat/src/model/http/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod guild;
|
6
foxchat/src/model/mod.rs
Normal file
6
foxchat/src/model/mod.rs
Normal 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
16
foxchat/src/model/user.rs
Normal 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,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue