Defined what auth server should do
This commit is contained in:
@@ -11,4 +11,5 @@ tokio = { version = "1.0", features = ["macros", "net", "rt-multi-thread"] }
|
|||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
serde = { version = "1.0.203", features = ["derive"] }
|
serde = { version = "1.0.203", features = ["derive"] }
|
||||||
chrono = { version = "0.4.24", features = ["serde"] }
|
chrono = { version = "0.4.24", features = ["serde"] }
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
|
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "mysql", "chrono" ] }
|
||||||
@@ -3,6 +3,7 @@ use std::future::Future;
|
|||||||
use std::net::{IpAddr, Ipv6Addr};
|
use std::net::{IpAddr, Ipv6Addr};
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use futures::{future, StreamExt};
|
use futures::{future, StreamExt};
|
||||||
|
use sqlx::mysql::MySqlPoolOptions;
|
||||||
use tarpc::server::{BaseChannel, Channel};
|
use tarpc::server::{BaseChannel, Channel};
|
||||||
use tarpc::server::incoming::Incoming;
|
use tarpc::server::incoming::Incoming;
|
||||||
use tarpc::tokio_serde::formats::Json;
|
use tarpc::tokio_serde::formats::Json;
|
||||||
@@ -17,6 +18,28 @@ async fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
|
|||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
|
let db_pool = MySqlPoolOptions::new()
|
||||||
|
.max_connections(64)
|
||||||
|
.connect(env::var("DATABASE_URL").expect("DATABASE_URL must be set").as_str()).await?;
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"CREATE DATABASE IF NOT EXISTS realmauth; USE realmauth;"
|
||||||
|
).fetch_one(&db_pool).await?;
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"CREATE TABLE IF NOT EXISTS user (
|
||||||
|
id SERIAL,
|
||||||
|
username VARCHAR(255) NOT NULL,
|
||||||
|
email VARCHAR(255) NOT NULL,
|
||||||
|
login_code INT(6),
|
||||||
|
tokens TEXT,
|
||||||
|
google_oauth VARCHAR(255),
|
||||||
|
apple_oauth VARCHAR(255),
|
||||||
|
github_oauth VARCHAR(255),
|
||||||
|
discord_oauth VARCHAR(255)
|
||||||
|
);"
|
||||||
|
).execute(&db_pool).await?;
|
||||||
|
|
||||||
let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), env::var("PORT").expect("PORT must be set").parse::<u16>().unwrap());
|
let server_addr = (IpAddr::V6(Ipv6Addr::LOCALHOST), env::var("PORT").expect("PORT must be set").parse::<u16>().unwrap());
|
||||||
|
|
||||||
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
||||||
|
|||||||
@@ -1,5 +1,35 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[tarpc::service]
|
#[tarpc::service]
|
||||||
pub trait RealmAuth {
|
pub trait RealmAuth {
|
||||||
async fn test(name: String) -> String;
|
async fn test(name: String) -> String;
|
||||||
|
async fn server_token_validation(username: String, server_id: String, domain: String, tarpc_port: u16) -> bool;
|
||||||
|
async fn create_account(username: String, email: String, avatar: String) -> Result<String, ErrorCode>;
|
||||||
|
async fn create_login_flow(username: String) -> ErrorCode;
|
||||||
|
async fn create_token_from_login(username: String, login_code: u16) -> Result<String, ErrorCode>;
|
||||||
|
|
||||||
|
//NOTE: Need to be the user
|
||||||
|
async fn change_email_flow(token: String) -> ErrorCode;
|
||||||
|
async fn resolve_email_flow(token: String, login_code: u16, new_email: String) -> ErrorCode;
|
||||||
|
async fn change_username(token: String, new_username: String) -> ErrorCode;
|
||||||
|
async fn change_avatar(token: String, avatar: String) -> ErrorCode;
|
||||||
|
//TODO:
|
||||||
|
// Create account
|
||||||
|
// Change email
|
||||||
|
// Change username
|
||||||
|
// Change/Upload/Delete avatar
|
||||||
|
// OAuth login, check against email, store token, take avatar
|
||||||
|
// Google, Apple, GitHub, Discord
|
||||||
|
// Get avatar
|
||||||
|
// Get all userdata if you are the user
|
||||||
|
// Server token validation
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum ErrorCode {
|
||||||
|
None,
|
||||||
|
Error,
|
||||||
|
EmailTaken,
|
||||||
|
UsernameTaken,
|
||||||
|
InvalidLoginCode,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user