yang_base/action/auth/
dto.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Deserialize, schemars::JsonSchema)]
15pub struct LoginInput {
16 pub username: String,
18 pub password: String,
20 #[serde(default)]
22 pub extra: serde_json::Value,
23}
24
25impl core::fmt::Debug for LoginInput {
27 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28 f.debug_struct("LoginInput")
29 .field("username", &self.username)
30 .field("password", &"***")
31 .field("extra", &self.extra)
32 .finish()
33 }
34}
35
36#[derive(Clone, Serialize, schemars::JsonSchema)]
38pub struct TokenPairResponse {
39 pub access_token: String,
41 pub refresh_token: String,
43}
44
45impl core::fmt::Debug for TokenPairResponse {
47 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48 f.debug_struct("TokenPairResponse")
49 .field(
50 "access_token",
51 &format!("***({} chars)", self.access_token.len()),
52 )
53 .field(
54 "refresh_token",
55 &format!("***({} chars)", self.refresh_token.len()),
56 )
57 .finish()
58 }
59}
60
61#[derive(Clone, Deserialize, schemars::JsonSchema)]
63#[serde(deny_unknown_fields)]
64pub struct RefreshInput {
65 pub refresh_token: String,
67}
68
69impl core::fmt::Debug for RefreshInput {
71 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72 f.debug_struct("RefreshInput")
73 .field(
74 "refresh_token",
75 &format!("***({} chars)", self.refresh_token.len()),
76 )
77 .finish()
78 }
79}
80
81#[derive(Clone, Serialize, schemars::JsonSchema)]
83pub struct AccessTokenResponse {
84 pub access_token: String,
86}
87
88impl core::fmt::Debug for AccessTokenResponse {
90 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
91 f.debug_struct("AccessTokenResponse")
92 .field(
93 "access_token",
94 &format!("***({} chars)", self.access_token.len()),
95 )
96 .finish()
97 }
98}
99
100#[derive(Clone, Deserialize, schemars::JsonSchema)]
105#[serde(deny_unknown_fields)]
106pub struct LogoutInput {
107 pub token: String,
109 #[serde(default)]
114 pub refresh_token: Option<String>,
115}
116
117impl core::fmt::Debug for LogoutInput {
119 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
120 f.debug_struct("LogoutInput")
121 .field("token", &format!("***({} chars)", self.token.len()))
122 .field(
123 "refresh_token",
124 &self
125 .refresh_token
126 .as_ref()
127 .map(|s| format!("***({} chars)", s.len())),
128 )
129 .finish()
130 }
131}
132
133#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
135pub struct MessageResponse {
136 pub message: String,
138}
139
140#[derive(Debug, Clone)]
145pub struct TokenPairClaims {
146 pub access: serde_json::Value,
148 pub refresh: serde_json::Value,
150}
151
152impl TokenPairClaims {
153 pub fn new(access: serde_json::Value) -> Self {
155 Self {
156 access,
157 refresh: serde_json::Value::Null,
158 }
159 }
160
161 pub fn with_refresh(mut self, refresh: serde_json::Value) -> Self {
163 self.refresh = refresh;
164 self
165 }
166}
167
168#[derive(Debug, Clone)]
170pub struct VerifiedSubject {
171 pub subject: String,
173 pub custom_claims: serde_json::Value,
175 pub refresh_claims: serde_json::Value,
177}
178
179impl VerifiedSubject {
180 pub fn new(subject: impl Into<String>) -> Self {
182 Self {
183 subject: subject.into(),
184 custom_claims: serde_json::Value::Null,
185 refresh_claims: serde_json::Value::Null,
186 }
187 }
188
189 pub fn with_claims(mut self, claims: serde_json::Value) -> Self {
191 self.custom_claims = claims;
192 self
193 }
194
195 pub fn with_refresh_claims(mut self, claims: serde_json::Value) -> Self {
197 self.refresh_claims = claims;
198 self
199 }
200
201 pub fn with_token_pair_claims(mut self, claims: TokenPairClaims) -> Self {
203 self.custom_claims = claims.access;
204 self.refresh_claims = claims.refresh;
205 self
206 }
207}