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  #[builder(into)]
19  pub player: PlayerId,
20  #[serde(default)]
21  #[builder(into)]
22  pub password: Option<Password>,
23}
24
25#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
26#[serde(rename_all = "camelCase")]
27#[cfg_attr(feature = "typescript", derive(TS))]
28#[cfg_attr(feature = "typescript", ts(export))]
29pub struct ValidateTokenRequest {
30  #[builder(start_fn, into)]
31  pub token: Token,
32}
33
34impl<T> From<T> for ValidateTokenRequest
35where
36  T: AsRef<str>,
37{
38  fn from(token: T) -> Self {
39    Self { token: Token::new(token) }
40  }
41}