1use serde::{Deserialize, Serialize};
3
4use crate::password::Password;
5
6#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
10pub enum AuthMethod {
11 Offline {
13 player_name: String,
15 uuid: String,
17 },
18 Mojang {
20 access_token: Password,
22 uuid: String,
24 player_name: String,
26 head_skin: Vec<u8>,
28 hat_skin: Vec<u8>,
30 },
31 Microsoft {
33 access_token: Password,
35 refresh_token: Password,
37 uuid: String,
39 xuid: String,
41 player_name: String,
43 head_skin: Vec<u8>,
45 hat_skin: Vec<u8>,
47 },
48 AuthlibInjector {
50 api_location: String,
52 server_name: String,
54 server_homepage: String,
56 server_meta: String,
58 access_token: Password,
60 uuid: String,
62 player_name: String,
64 head_skin: Vec<u8>,
66 hat_skin: Vec<u8>,
68 },
69}
70
71pub(crate) mod mojang {
72 use serde::{Deserialize, Serialize};
73
74 use crate::password::Password;
75
76 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
77 #[serde(rename_all = "camelCase")]
78 pub(crate) struct AuthenticateBody {
79 pub agent: AuthenticateAgent,
80 pub username: String,
81 pub password: Password,
82 #[serde(skip_serializing_if = "String::is_empty")]
83 pub client_token: String,
84 pub request_user: bool,
85 }
86
87 impl Default for AuthenticateBody {
88 fn default() -> Self {
89 Self {
90 request_user: true,
91 username: "".into(),
92 password: "".into(),
93 client_token: "".into(),
94 agent: Default::default(),
95 }
96 }
97 }
98
99 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
100 pub(crate) struct AuthenticateAgent {
101 pub name: String,
102 pub version: usize,
103 }
104
105 impl Default for AuthenticateAgent {
106 fn default() -> Self {
107 Self {
108 name: "Minecraft".into(),
109 version: 1,
110 }
111 }
112 }
113
114 #[derive(Debug, Deserialize, PartialEq, Eq)]
115 #[serde(rename_all = "camelCase")]
116 pub(crate) struct AuthenticateResponse {
117 pub access_token: Password,
118 pub client_token: String,
119 pub available_profiles: Vec<AvaliableProfile>,
120 pub selected_profile: Option<AvaliableProfile>,
121 }
122
123 #[derive(Debug, Serialize, PartialEq, Eq)]
124 #[serde(rename_all = "camelCase")]
125 pub(crate) struct ValidateResponse {
126 pub access_token: Password,
127 pub client_token: String,
128 }
129
130 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
131 pub(crate) struct AvaliableProfile {
132 pub name: String,
133 pub id: String,
134 }
135
136 #[derive(Debug, Deserialize, PartialEq, Eq, Clone, Default)]
138 #[serde(rename_all = "camelCase")]
139 pub struct ErrorResponse {
140 pub error: String,
142 pub error_message: String,
144 #[serde(default)]
146 pub cause: String,
147 }
148
149 #[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
150 pub(crate) struct ProfileResponse {
151 pub id: String,
152 pub name: String,
153 pub properties: Vec<ProfilePropertie>,
154 }
155
156 #[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
157 pub(crate) struct ProfilePropertie {
158 pub name: String,
159 pub value: String,
160 }
161
162 #[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
163 #[serde(rename_all = "camelCase")]
164 pub(crate) struct ProfileTexture {
165 pub timestamp: u64,
166 pub profile_id: String,
167 pub profile_name: String,
168 pub textures: Option<TextureData>,
169 }
170
171 #[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
172 pub(crate) struct TextureData {
173 #[serde(rename = "SKIN")]
174 pub skin: Option<SkinData>,
175 #[serde(rename = "CAPE")]
176 pub cape: Option<SkinData>,
177 }
178
179 #[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
180 pub(crate) struct SkinData {
181 pub url: String,
182 }
183}