ddnet_accounts_shared/client/credential_auth_token.rs
1use serde::{Deserialize, Serialize};
2use strum::{EnumString, IntoStaticStr};
3
4/// The operation for what this authorized credential token should do.
5#[derive(Debug, Serialize, Deserialize, IntoStaticStr, EnumString, Clone, Copy, PartialEq, Eq)]
6#[strum(serialize_all = "lowercase")]
7pub enum CredentialAuthTokenOperation {
8 /// Login using these credentials.
9 Login,
10 /// Link the credential to an account
11 /// (e.g. email or steam).
12 LinkCredential,
13 /// Unlink the credential from its account
14 /// (e.g. email or steam).
15 /// If the credential is the last bound to
16 /// the account this operation will fail and
17 /// [`super::account_token::AccountTokenOperation::Delete`]
18 /// should be used instead.
19 UnlinkCredential,
20}
21
22/// A secret key used for a verification process.
23pub type SecretKey = [u8; 32];
24
25/// A request for a token that is used for the
26/// email credential operation.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct CredentialAuthTokenEmailRequest {
29 /// The email of the account to log into.
30 pub email: email_address::EmailAddress,
31 /// A secret key that was generated through
32 /// a verification process (e.g. captchas).
33 /// It is optional, since these verification
34 /// processes differ from user to user.
35 pub secret_key: Option<SecretKey>,
36 /// The operation that this credential authorization
37 /// should perform.
38 pub op: CredentialAuthTokenOperation,
39}
40
41/// A request for a token that is used for the
42/// steam credential operation.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct CredentialAuthTokenSteamRequest {
45 /// The session token generated on the steam client
46 /// for the account to log into.
47 pub steam_ticket: Vec<u8>,
48 /// A secret key that was generated through
49 /// a verification process (e.g. captchas).
50 /// It is optional, since these verification
51 /// processes differ from user to user.
52 pub secret_key: Option<SecretKey>,
53 /// The operation that this credential authorization
54 /// should perform.
55 pub op: CredentialAuthTokenOperation,
56}