Skip to main content

nil_payload/request/
auth.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use bon::Builder;
5use nil_core::player::PlayerId;
6use nil_crypto::password::Password;
7use nil_server_types::auth::Token;
8use serde::{Deserialize, Serialize};
9
10#[cfg(feature = "typescript")]
11use ts_rs::TS;
12
13#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
14#[serde(rename_all = "camelCase")]
15#[cfg_attr(feature = "typescript", derive(TS))]
16#[cfg_attr(feature = "typescript", ts(export, optional_fields = nullable))]
17pub struct AuthorizeRequest {
18  pub player: PlayerId,
19  #[serde(default)]
20  pub password: Option<Password>,
21}
22
23#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
24#[serde(rename_all = "camelCase")]
25#[cfg_attr(feature = "typescript", derive(TS))]
26#[cfg_attr(feature = "typescript", ts(export))]
27pub struct ValidateTokenRequest {
28  pub token: Token,
29}
30
31impl<T> From<T> for ValidateTokenRequest
32where
33  T: AsRef<str>,
34{
35  fn from(token: T) -> Self {
36    Self { token: Token::new(token) }
37  }
38}