Skip to main content

elemental_core/auth/
credential.rs

1use serde::{Deserialize, Serialize};
2
3/// Credential passed to the game process for one launch.
4///
5/// This value is derived from an [`crate::auth::accounts::Account`] and is
6/// intentionally not persisted.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Credential {
9    pub username: String,
10    pub uuid: String,
11    pub access_token: String,
12    pub kind: CredentialKind,
13    pub xuid: Option<String>,
14    pub client_id: Option<String>,
15    /// Yggdrasil API root for authlib-injector.
16    ///
17    /// Kept as an explicit field for now since authlib-injector is the only
18    /// external auth protocol supported; can be generalized into a typed auth
19    /// protocol extension if additional external protocols are added later.
20    #[cfg(feature = "yggdrasil-auth")]
21    pub auth_server: Option<String>,
22}
23
24impl Credential {
25    #[cfg(feature = "yggdrasil-auth")]
26    pub fn with_auth_server(mut self, auth_server: impl Into<String>) -> Self {
27        self.auth_server = Some(auth_server.into());
28        self
29    }
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
33#[serde(rename_all = "lowercase")]
34pub enum CredentialKind {
35    Legacy,
36    Mojang,
37    Msa,
38}