use serde::{Deserialize, Serialize};
use super::profile::GameProfile;
use crate::util::impl_redacted_debug;
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Agent {
pub name: String,
pub version: u32,
}
impl Agent {
pub fn minecraft() -> Self {
Self {
name: "Minecraft".to_string(),
version: 1,
}
}
}
impl Default for Agent {
fn default() -> Self {
Self::minecraft()
}
}
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthenticateRequest {
pub agent: Agent,
pub username: String,
pub password: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client_token: Option<String>,
#[serde(default)]
pub request_user: bool,
}
impl_redacted_debug!(AuthenticateRequest {
agent, username, request_user;
redacted: password;
optional_redacted: client_token,
});
impl AuthenticateRequest {
pub fn new(
username: impl Into<String>,
password: impl Into<String>,
client_token: Option<String>,
request_user: bool,
) -> Self {
Self {
agent: Agent::minecraft(),
username: username.into(),
password: password.into(),
client_token,
request_user,
}
}
}
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AuthenticateResponse {
pub access_token: String,
pub client_token: String,
#[serde(default)]
pub available_profiles: Vec<GameProfile>,
#[serde(default)]
pub selected_profile: Option<GameProfile>,
#[serde(default)]
pub user: Option<UserObject>,
}
impl_redacted_debug!(AuthenticateResponse {
available_profiles, selected_profile, user;
redacted: access_token, client_token,
});
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RefreshRequest {
pub access_token: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client_token: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub selected_profile: Option<GameProfile>,
#[serde(default)]
pub request_user: bool,
}
impl_redacted_debug!(RefreshRequest {
selected_profile, request_user;
redacted: access_token;
optional_redacted: client_token,
});
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RefreshResponse {
pub access_token: String,
pub client_token: String,
#[serde(default)]
pub selected_profile: Option<GameProfile>,
#[serde(default)]
pub user: Option<UserObject>,
}
impl_redacted_debug!(RefreshResponse {
selected_profile, user;
redacted: access_token, client_token,
});
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenPairRequest {
pub access_token: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client_token: Option<String>,
}
impl_redacted_debug!(TokenPairRequest {
;
redacted: access_token;
optional_redacted: client_token,
});
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignoutRequest {
pub username: String,
pub password: String,
}
impl_redacted_debug!(SignoutRequest {
username;
redacted: password,
});
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct JoinServerRequest {
pub access_token: String,
pub selected_profile: String,
pub server_id: String,
}
impl_redacted_debug!(JoinServerRequest {
selected_profile, server_id;
redacted: access_token,
});
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct UserObject {
pub id: String,
#[serde(default)]
pub properties: Vec<UserProperty>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct UserProperty {
pub name: String,
pub value: String,
}