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 nil_core::player::PlayerId;
5use nil_crypto::password::Password;
6use nil_server_types::auth::Token;
7use serde::{Deserialize, Serialize};
8
9#[cfg(feature = "typescript")]
10use ts_rs::TS;
11
12#[derive(Clone, Debug, Deserialize, Serialize)]
13#[serde(rename_all = "camelCase")]
14#[cfg_attr(feature = "typescript", derive(TS))]
15#[cfg_attr(feature = "typescript", ts(export, optional_fields = nullable))]
16pub struct AuthorizeRequest {
17  pub player: PlayerId,
18  #[serde(default)]
19  pub password: Option<Password>,
20}
21
22#[derive(Clone, Debug, Deserialize, Serialize)]
23#[serde(rename_all = "camelCase")]
24#[cfg_attr(feature = "typescript", derive(TS))]
25#[cfg_attr(feature = "typescript", ts(export))]
26pub struct ValidateTokenRequest {
27  pub token: Token,
28}
29
30impl<T> From<T> for ValidateTokenRequest
31where
32  T: AsRef<str>,
33{
34  fn from(token: T) -> Self {
35    Self { token: Token::new(token) }
36  }
37}