diff --git a/src/proto.rs b/src/proto.rs index 8a801b3..4b3b8bd 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -10,7 +10,7 @@ pub struct Error { pub cause: String, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct Agent { pub name: String, pub version: u32, @@ -23,7 +23,17 @@ pub struct Property { pub signature: Option, } -#[derive(Serialize, Deserialize)] +impl Property { + pub fn default_skin() -> Property { + Property { + name: "textures".into(), + value: "ewogICJ0aW1lc3RhbXAiIDogMTY3NDQwNDEzNjYyMiwKICAicHJvZmlsZUlkIiA6ICJjYjIzZWZhOWY1N2U0ZTQyOGE0MDU2OTM4NDlhODAxZiIsCiAgInByb2ZpbGVOYW1lIiA6ICJWMUdHTyIsCiAgInNpZ25hdHVyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9jNzgzMWE4MjAwN2FkNDNjY2ZkMGYyNThiMmJjNDQyYmI1MmE2ZTYxOWJlYzZmZjg5NDRkZWFkOWFhYTQ3MjVjIgogICAgfQogIH0KfQ==".into(), + signature: Some("pnWuF/KetMbydKaBAEXmoI2evgjvafa0CBJhNnph5JE7SN2JXZjdgy/SHLZLBMZoWBW7JRgpz0pFPhXOtPA5NtJYSKWQPXP04DY+x8Am3K3H1LqW92M8EPR5kJl+5KvlARASiqjnlobDoDIMvdG1748bVDUHY5GdlCZFaUQHmGiq9IWSnG65Ejgc/O1SkP/x6MaQrqW8XgNyR/f4oTOoYeSYThxsfqGmEgFl8SmcDYiUDwRXdJThsRRQMS98GMMWlQ0ujLjg6MGLdLwoNf4R3hU1vIB3o6BhXt+GydKHhy0xMtmqmYeS7YB6gAlhKG+YAVJisFIfwNGPLUt1qlIi8aMav+pw0yBqmzD8Uq8cqJrYdokB7kBE0t+6iHUX6nSXt0zUZSE+sQ4Hd5AQEV7rwcYTVYdmCA8RtlZZKK0zXQXTiuRpaDHDe9UYe5CNEmDnq1Plbz7w7JNMnNEVhOlCRJXRzrc6FHLWZT46QOC+Vhqz3/rpi7qEopgBLusQSJIox2lh6Ccc1tP/AZbFQjdPcks6+gpFOBYqF/+zcCJD/1UkXe3diIkgX9SqHIKPM0OtpsHO5Z4+SjtNIKUGUi7qjfe4NFSg+bUX2unsha9oHEaGir93cCIBO+liDlk5ZNc60wtncuoTnLtmKvlXHTZiBMGMRflIXkHQX5n8HYmC0LE=".into()), + } + } +} + +#[derive(Serialize, Deserialize, Debug)] pub struct User { pub id: Uuid, pub username: String, @@ -38,23 +48,23 @@ pub struct SessionUser { pub properties: Option>, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, Debug)] pub struct Profile { pub name: String, pub id: Uuid, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct AuthenticateRequest { pub agent: Agent, pub username: String, pub password: String, - pub clientToken: Option, + pub clientToken: Option, pub requestUser: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct AuthenticateResponse { pub user: User, pub clientToken: String, @@ -63,7 +73,7 @@ pub struct AuthenticateResponse { pub selectedProfile: Profile, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct RefreshRequest { pub accessToken: String, pub clientToken: String, @@ -71,7 +81,7 @@ pub struct RefreshRequest { pub requestUser: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct RefreshResponse { pub accessToken: String, pub clientToken: String, @@ -79,7 +89,7 @@ pub struct RefreshResponse { pub user: Option, } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct ValidateRequest { pub accessToken: String, pub clientToken: Option, @@ -93,7 +103,7 @@ pub struct SignoutRequest { -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Debug)] pub struct JoinRequest { pub accessToken: String, pub selectedProfile: Uuid, diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 407a93f..da49d18 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -2,11 +2,13 @@ use axum::{extract::State, Json, http::StatusCode}; use chrono::Utc; use sea_orm::{EntityTrait, QueryFilter, ColumnTrait, ActiveValue::NotSet, Set}; use uuid::Uuid; +use tracing::{info, warn}; use crate::{entities, AppState, proto}; pub async fn validate(State(state): State, Json(payload): Json) -> StatusCode { + info!(target: "AUTH", "[VALIDATE] called with {:?}", payload); let token = entities::token::Entity::find().filter( entities::token::Column::AccessToken.eq(payload.accessToken) ).one(&state.db).await.unwrap(); @@ -14,11 +16,13 @@ pub async fn validate(State(state): State, Json(payload): Json, Json(payload): Json) -> Result, StatusCode> { + info!(target: "AUTH", "[REFRESH] called with {:?}", payload); let token = entities::token::Entity::find().filter( entities::token::Column::AccessToken.eq(payload.accessToken.clone()) ).one(&state.db).await.unwrap(); @@ -26,37 +30,31 @@ pub async fn refresh(State(state): State, Json(payload): Json, Json(payload): Json) -> Result, StatusCode> { + info!(target: "AUTH", "[AUTHENTICATE] called with {:?}", payload); let user = entities::user::Entity::find().filter( entities::user::Column::Name.eq(payload.username) ).one(&state.db).await.unwrap(); @@ -71,20 +69,20 @@ pub async fn authenticate(State(state): State, Json(payload): Json, Json(payload): Json) -> StatusCode { + info!(target: "SESSION", "[JOIN] called with {:?}", payload); let user = entities::user::Entity::find().filter( entities::user::Column::Uuid.eq(payload.selectedProfile) ).one(&state.db).await.unwrap().unwrap(); @@ -31,6 +32,7 @@ pub async fn join(State(state): State, Json(payload): Json, Query(query): Query>) -> Result, StatusCode> { let username = query.get("username").unwrap().clone(); let server_id = query.get("serverId").unwrap(); + info!(target: "SESSION", "[HAS_JOINED] called with user:{} server:{}", username, server_id); let user = entities::user::Entity::find().filter( entities::user::Column::Name.eq(username.clone()) @@ -45,29 +47,23 @@ pub async fn has_joined(State(state): State, Query(query): Query {:?}", response); + info!(target: "SESSION", "[HAS_JOINED] server found user -> {:?}", response); Ok(Json(response)) } else { - warn!(target: "hasJOINED", "server found user but join was late or for another server"); + warn!(target: "SESSION", "[HAS_JOINED] server found user but join was late or for another server"); Err(StatusCode::NOT_FOUND) } }, None => { - warn!(target: "hasJOINED", "server didn't find user"); + warn!(target: "SESSION", "[HAS_JOINED] server didn't find user"); Err(StatusCode::NOT_FOUND) }, } }, None => { - warn!(target: "hasJOINED", "invalid UUID"); + warn!(target: "SESSION", "[HAS_JOINED] invalid UUID"); Err(StatusCode::NOT_FOUND) }, } @@ -82,7 +78,7 @@ pub async fn profile(State(state): State, Path(user_id): Path) - Ok(Json(proto::SessionUser { id: u.uuid, name: u.name, - properties: Some(vec![]), + properties: Some(vec![ proto::Property::default_skin() ]), })) } else { Err(StatusCode::NOT_FOUND)