systemprompt_identifiers/
oauth.rs

1use crate::{DbValue, ToDbValue};
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
7#[cfg_attr(feature = "sqlx", sqlx(transparent))]
8#[serde(transparent)]
9pub struct RefreshTokenId(String);
10
11impl RefreshTokenId {
12    pub fn new(id: impl Into<String>) -> Self {
13        Self(id.into())
14    }
15
16    pub fn as_str(&self) -> &str {
17        &self.0
18    }
19}
20
21impl fmt::Display for RefreshTokenId {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        write!(f, "{}", self.0)
24    }
25}
26
27impl From<String> for RefreshTokenId {
28    fn from(s: String) -> Self {
29        Self(s)
30    }
31}
32
33impl From<&str> for RefreshTokenId {
34    fn from(s: &str) -> Self {
35        Self(s.to_string())
36    }
37}
38
39impl AsRef<str> for RefreshTokenId {
40    fn as_ref(&self) -> &str {
41        &self.0
42    }
43}
44
45impl ToDbValue for RefreshTokenId {
46    fn to_db_value(&self) -> DbValue {
47        DbValue::String(self.0.clone())
48    }
49}
50
51impl ToDbValue for &RefreshTokenId {
52    fn to_db_value(&self) -> DbValue {
53        DbValue::String(self.0.clone())
54    }
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
58#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
59#[cfg_attr(feature = "sqlx", sqlx(transparent))]
60#[serde(transparent)]
61pub struct AccessTokenId(String);
62
63impl AccessTokenId {
64    pub fn new(id: impl Into<String>) -> Self {
65        Self(id.into())
66    }
67
68    pub fn as_str(&self) -> &str {
69        &self.0
70    }
71}
72
73impl fmt::Display for AccessTokenId {
74    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75        write!(f, "{}", self.0)
76    }
77}
78
79impl From<String> for AccessTokenId {
80    fn from(s: String) -> Self {
81        Self(s)
82    }
83}
84
85impl From<&str> for AccessTokenId {
86    fn from(s: &str) -> Self {
87        Self(s.to_string())
88    }
89}
90
91impl AsRef<str> for AccessTokenId {
92    fn as_ref(&self) -> &str {
93        &self.0
94    }
95}
96
97impl ToDbValue for AccessTokenId {
98    fn to_db_value(&self) -> DbValue {
99        DbValue::String(self.0.clone())
100    }
101}
102
103impl ToDbValue for &AccessTokenId {
104    fn to_db_value(&self) -> DbValue {
105        DbValue::String(self.0.clone())
106    }
107}
108
109#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
110#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
111#[cfg_attr(feature = "sqlx", sqlx(transparent))]
112#[serde(transparent)]
113pub struct AuthorizationCode(String);
114
115impl AuthorizationCode {
116    pub fn new(code: impl Into<String>) -> Self {
117        Self(code.into())
118    }
119
120    pub fn as_str(&self) -> &str {
121        &self.0
122    }
123}
124
125impl fmt::Display for AuthorizationCode {
126    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127        write!(f, "{}", self.0)
128    }
129}
130
131impl From<String> for AuthorizationCode {
132    fn from(s: String) -> Self {
133        Self(s)
134    }
135}
136
137impl From<&str> for AuthorizationCode {
138    fn from(s: &str) -> Self {
139        Self(s.to_string())
140    }
141}
142
143impl AsRef<str> for AuthorizationCode {
144    fn as_ref(&self) -> &str {
145        &self.0
146    }
147}
148
149impl ToDbValue for AuthorizationCode {
150    fn to_db_value(&self) -> DbValue {
151        DbValue::String(self.0.clone())
152    }
153}
154
155impl ToDbValue for &AuthorizationCode {
156    fn to_db_value(&self) -> DbValue {
157        DbValue::String(self.0.clone())
158    }
159}
160
161#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
162#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
163#[cfg_attr(feature = "sqlx", sqlx(transparent))]
164#[serde(transparent)]
165pub struct ChallengeId(String);
166
167impl ChallengeId {
168    pub fn new(id: impl Into<String>) -> Self {
169        Self(id.into())
170    }
171
172    pub fn as_str(&self) -> &str {
173        &self.0
174    }
175}
176
177impl fmt::Display for ChallengeId {
178    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179        write!(f, "{}", self.0)
180    }
181}
182
183impl From<String> for ChallengeId {
184    fn from(s: String) -> Self {
185        Self(s)
186    }
187}
188
189impl From<&str> for ChallengeId {
190    fn from(s: &str) -> Self {
191        Self(s.to_string())
192    }
193}
194
195impl AsRef<str> for ChallengeId {
196    fn as_ref(&self) -> &str {
197        &self.0
198    }
199}
200
201impl ToDbValue for ChallengeId {
202    fn to_db_value(&self) -> DbValue {
203        DbValue::String(self.0.clone())
204    }
205}
206
207impl ToDbValue for &ChallengeId {
208    fn to_db_value(&self) -> DbValue {
209        DbValue::String(self.0.clone())
210    }
211}