use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, schemars::JsonSchema)]
pub struct LoginInput {
pub username: String,
pub password: String,
#[serde(default)]
pub extra: serde_json::Value,
}
impl core::fmt::Debug for LoginInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("LoginInput")
.field("username", &self.username)
.field("password", &"***")
.field("extra", &self.extra)
.finish()
}
}
#[derive(Clone, Serialize, schemars::JsonSchema)]
pub struct TokenPairResponse {
pub access_token: String,
pub refresh_token: String,
}
impl core::fmt::Debug for TokenPairResponse {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("TokenPairResponse")
.field(
"access_token",
&format!("***({} chars)", self.access_token.len()),
)
.field(
"refresh_token",
&format!("***({} chars)", self.refresh_token.len()),
)
.finish()
}
}
#[derive(Clone, Deserialize, schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct RefreshInput {
pub refresh_token: String,
}
impl core::fmt::Debug for RefreshInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("RefreshInput")
.field(
"refresh_token",
&format!("***({} chars)", self.refresh_token.len()),
)
.finish()
}
}
#[derive(Clone, Serialize, schemars::JsonSchema)]
pub struct AccessTokenResponse {
pub access_token: String,
}
impl core::fmt::Debug for AccessTokenResponse {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("AccessTokenResponse")
.field(
"access_token",
&format!("***({} chars)", self.access_token.len()),
)
.finish()
}
}
#[derive(Clone, Deserialize, schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct LogoutInput {
pub token: String,
}
impl core::fmt::Debug for LogoutInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("LogoutInput")
.field("token", &format!("***({} chars)", self.token.len()))
.finish()
}
}
#[derive(Debug, Clone, Serialize, schemars::JsonSchema)]
pub struct MessageResponse {
pub message: String,
}
#[derive(Debug, Clone)]
pub struct TokenPairClaims {
pub access: serde_json::Value,
pub refresh: serde_json::Value,
}
impl TokenPairClaims {
pub fn new(access: serde_json::Value) -> Self {
Self {
access,
refresh: serde_json::Value::Null,
}
}
pub fn with_refresh(mut self, refresh: serde_json::Value) -> Self {
self.refresh = refresh;
self
}
}
#[derive(Debug, Clone)]
pub struct VerifiedSubject {
pub subject: String,
pub custom_claims: serde_json::Value,
pub refresh_claims: serde_json::Value,
}
impl VerifiedSubject {
pub fn new(subject: impl Into<String>) -> Self {
Self {
subject: subject.into(),
custom_claims: serde_json::Value::Null,
refresh_claims: serde_json::Value::Null,
}
}
pub fn with_claims(mut self, claims: serde_json::Value) -> Self {
self.custom_claims = claims;
self
}
pub fn with_refresh_claims(mut self, claims: serde_json::Value) -> Self {
self.refresh_claims = claims;
self
}
pub fn with_token_pair_claims(mut self, claims: TokenPairClaims) -> Self {
self.custom_claims = claims.access;
self.refresh_claims = claims.refresh;
self
}
}