You've already forked AstralRinth
forked from didirus/AstralRinth
* Fix not being able to connect to local friends socket * Start basic work on tunneling protocol and move some code into a common crate * Commonize message serialization logic * Serialize Base62Ids as u64 when human-readability is not required * Move ActiveSockets tuple into struct * Make CI run when rust-common is updated CI is currently broken for labrinth, however * Fix theseus-release.yml to reference itself correctly * Implement Labrinth side of tunneling * Implement non-friend part of theseus tunneling * Implement client-side except for socket loop * Implement the socket loop Doesn't work though. Debugging time! * Fix config.rs * Fix deadlock in labrinth socket handling * Update dockerfile * switch to workspace prepare at root level * Wait for connection before tunneling in playground * Move rust-common into labrinth * Remove rust-common references from Actions * Revert "Update dockerfile" This reverts commit 3caad59bb474ce425d0b8928d7cee7ae1a5011bd. * Fix Docker build * Rebuild Theseus if common code changes * Allow multiple connections from the same user * Fix test building * Move FriendSocketListening and FriendSocketStoppedListening to non-panicking TODO for now * Make message_serialization macro take varargs for binary messages * Improve syntax of message_serialization macro * Remove the ability to connect to a virtual socket, and disable the ability to listen on one * Allow the app to compile without running labrinth * Clippy fix * Update Rust and Clippy fix again --------- Co-authored-by: Jai A <jaiagr+gpg@pm.me>
123 lines
4.5 KiB
Rust
123 lines
4.5 KiB
Rust
pub mod checks;
|
|
pub mod email;
|
|
pub mod oauth;
|
|
pub mod templates;
|
|
pub mod validate;
|
|
pub use crate::auth::email::send_email;
|
|
pub use checks::{
|
|
filter_enlisted_projects_ids, filter_enlisted_version_ids,
|
|
filter_visible_collections, filter_visible_project_ids,
|
|
filter_visible_projects,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
// pub use pat::{generate_pat, PersonalAccessToken};
|
|
pub use validate::{check_is_moderator_from_headers, get_user_from_headers};
|
|
|
|
use crate::file_hosting::FileHostingError;
|
|
use crate::models::error::ApiError;
|
|
use actix_web::http::StatusCode;
|
|
use actix_web::HttpResponse;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AuthenticationError {
|
|
#[error("Environment Error")]
|
|
Env(#[from] dotenvy::Error),
|
|
#[error("An unknown database error occurred: {0}")]
|
|
Sqlx(#[from] sqlx::Error),
|
|
#[error("Database Error: {0}")]
|
|
Database(#[from] crate::database::models::DatabaseError),
|
|
#[error("Error while parsing JSON: {0}")]
|
|
SerDe(#[from] serde_json::Error),
|
|
#[error("Error while communicating to external provider")]
|
|
Reqwest(#[from] reqwest::Error),
|
|
#[error("Error uploading user profile picture")]
|
|
FileHosting(#[from] FileHostingError),
|
|
#[error("Error while decoding PAT: {0}")]
|
|
Decoding(#[from] crate::common::ids::DecodingError),
|
|
#[error("{0}")]
|
|
Mail(#[from] email::MailError),
|
|
#[error("Invalid Authentication Credentials")]
|
|
InvalidCredentials,
|
|
#[error("Authentication method was not valid")]
|
|
InvalidAuthMethod,
|
|
#[error("GitHub Token from incorrect Client ID")]
|
|
InvalidClientId,
|
|
#[error("User email/account is already registered on Modrinth")]
|
|
DuplicateUser,
|
|
#[error("Invalid state sent, you probably need to get a new websocket")]
|
|
SocketError,
|
|
#[error("Invalid callback URL specified")]
|
|
Url,
|
|
}
|
|
|
|
impl actix_web::ResponseError for AuthenticationError {
|
|
fn status_code(&self) -> StatusCode {
|
|
match self {
|
|
AuthenticationError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AuthenticationError::Sqlx(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AuthenticationError::Database(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::SerDe(..) => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::Reqwest(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::InvalidCredentials => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::Decoding(..) => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::Mail(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
AuthenticationError::InvalidAuthMethod => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::InvalidClientId => StatusCode::UNAUTHORIZED,
|
|
AuthenticationError::Url => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::FileHosting(..) => {
|
|
StatusCode::INTERNAL_SERVER_ERROR
|
|
}
|
|
AuthenticationError::DuplicateUser => StatusCode::BAD_REQUEST,
|
|
AuthenticationError::SocketError => StatusCode::BAD_REQUEST,
|
|
}
|
|
}
|
|
|
|
fn error_response(&self) -> HttpResponse {
|
|
HttpResponse::build(self.status_code()).json(ApiError {
|
|
error: self.error_name(),
|
|
description: self.to_string(),
|
|
})
|
|
}
|
|
}
|
|
|
|
impl AuthenticationError {
|
|
pub fn error_name(&self) -> &'static str {
|
|
match self {
|
|
AuthenticationError::Env(..) => "environment_error",
|
|
AuthenticationError::Sqlx(..) => "database_error",
|
|
AuthenticationError::Database(..) => "database_error",
|
|
AuthenticationError::SerDe(..) => "invalid_input",
|
|
AuthenticationError::Reqwest(..) => "network_error",
|
|
AuthenticationError::InvalidCredentials => "invalid_credentials",
|
|
AuthenticationError::Decoding(..) => "decoding_error",
|
|
AuthenticationError::Mail(..) => "mail_error",
|
|
AuthenticationError::InvalidAuthMethod => "invalid_auth_method",
|
|
AuthenticationError::InvalidClientId => "invalid_client_id",
|
|
AuthenticationError::Url => "url_error",
|
|
AuthenticationError::FileHosting(..) => "file_hosting",
|
|
AuthenticationError::DuplicateUser => "duplicate_user",
|
|
AuthenticationError::SocketError => "socket",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(
|
|
Serialize, Deserialize, Default, Eq, PartialEq, Clone, Copy, Debug,
|
|
)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum AuthProvider {
|
|
#[default]
|
|
GitHub,
|
|
Discord,
|
|
Microsoft,
|
|
GitLab,
|
|
Google,
|
|
Steam,
|
|
PayPal,
|
|
}
|