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}
110
111impl core::fmt::Debug for LogoutInput {
113 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
114 f.debug_struct("LogoutInput")
115 .field("token", &format!("***({} chars)", self.token.len()))
116 .finish()
117 }
118}
119
120#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
122pub struct MessageResponse {
123 pub message: String,
125}
126
127#[derive(Debug, Clone)]
132pub struct TokenPairClaims {
133 pub access: serde_json::Value,
135 pub refresh: serde_json::Value,
137}
138
139impl TokenPairClaims {
140 pub fn new(access: serde_json::Value) -> Self {
142 Self {
143 access,
144 refresh: serde_json::Value::Null,
145 }
146 }
147
148 pub fn with_refresh(mut self, refresh: serde_json::Value) -> Self {
150 self.refresh = refresh;
151 self
152 }
153}
154
155#[derive(Debug, Clone)]
157pub struct VerifiedSubject {
158 pub subject: String,
160 pub custom_claims: serde_json::Value,
162 pub refresh_claims: serde_json::Value,
164}
165
166impl VerifiedSubject {
167 pub fn new(subject: impl Into<String>) -> Self {
169 Self {
170 subject: subject.into(),
171 custom_claims: serde_json::Value::Null,
172 refresh_claims: serde_json::Value::Null,
173 }
174 }
175
176 pub fn with_claims(mut self, claims: serde_json::Value) -> Self {
178 self.custom_claims = claims;
179 self
180 }
181
182 pub fn with_refresh_claims(mut self, claims: serde_json::Value) -> Self {
184 self.refresh_claims = claims;
185 self
186 }
187
188 pub fn with_token_pair_claims(mut self, claims: TokenPairClaims) -> Self {
190 self.custom_claims = claims.access;
191 self.refresh_claims = claims.refresh;
192 self
193 }
194}