this repo has no description
1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_json::Value as JsonValue;
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct RequestId(pub String);
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct TokenId(pub String);
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct DeviceId(pub String);
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct SessionId(pub String);
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct Code(pub String);
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct RefreshToken(pub String);
16impl RequestId {
17 pub fn generate() -> Self {
18 Self(format!("urn:ietf:params:oauth:request_uri:{}", uuid::Uuid::new_v4()))
19 }
20}
21impl TokenId {
22 pub fn generate() -> Self {
23 Self(uuid::Uuid::new_v4().to_string())
24 }
25}
26impl DeviceId {
27 pub fn generate() -> Self {
28 Self(uuid::Uuid::new_v4().to_string())
29 }
30}
31impl SessionId {
32 pub fn generate() -> Self {
33 Self(uuid::Uuid::new_v4().to_string())
34 }
35}
36impl Code {
37 pub fn generate() -> Self {
38 use rand::Rng;
39 let bytes: [u8; 32] = rand::thread_rng().r#gen();
40 Self(base64::Engine::encode(
41 &base64::engine::general_purpose::URL_SAFE_NO_PAD,
42 bytes,
43 ))
44 }
45}
46impl RefreshToken {
47 pub fn generate() -> Self {
48 use rand::Rng;
49 let bytes: [u8; 32] = rand::thread_rng().r#gen();
50 Self(base64::Engine::encode(
51 &base64::engine::general_purpose::URL_SAFE_NO_PAD,
52 bytes,
53 ))
54 }
55}
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(tag = "method")]
58pub enum ClientAuth {
59 #[serde(rename = "none")]
60 None,
61 #[serde(rename = "client_secret_basic")]
62 SecretBasic { client_secret: String },
63 #[serde(rename = "client_secret_post")]
64 SecretPost { client_secret: String },
65 #[serde(rename = "private_key_jwt")]
66 PrivateKeyJwt { client_assertion: String },
67}
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct AuthorizationRequestParameters {
70 pub response_type: String,
71 pub client_id: String,
72 pub redirect_uri: String,
73 pub scope: Option<String>,
74 pub state: Option<String>,
75 pub code_challenge: String,
76 pub code_challenge_method: String,
77 pub login_hint: Option<String>,
78 pub dpop_jkt: Option<String>,
79 #[serde(flatten)]
80 pub extra: Option<JsonValue>,
81}
82#[derive(Debug, Clone)]
83pub struct RequestData {
84 pub client_id: String,
85 pub client_auth: Option<ClientAuth>,
86 pub parameters: AuthorizationRequestParameters,
87 pub expires_at: DateTime<Utc>,
88 pub did: Option<String>,
89 pub device_id: Option<String>,
90 pub code: Option<String>,
91}
92#[derive(Debug, Clone)]
93pub struct DeviceData {
94 pub session_id: String,
95 pub user_agent: Option<String>,
96 pub ip_address: String,
97 pub last_seen_at: DateTime<Utc>,
98}
99#[derive(Debug, Clone)]
100pub struct TokenData {
101 pub did: String,
102 pub token_id: String,
103 pub created_at: DateTime<Utc>,
104 pub updated_at: DateTime<Utc>,
105 pub expires_at: DateTime<Utc>,
106 pub client_id: String,
107 pub client_auth: ClientAuth,
108 pub device_id: Option<String>,
109 pub parameters: AuthorizationRequestParameters,
110 pub details: Option<JsonValue>,
111 pub code: Option<String>,
112 pub current_refresh_token: Option<String>,
113 pub scope: Option<String>,
114}
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct AuthorizedClientData {
117 pub scope: Option<String>,
118 pub remember: bool,
119}
120#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct OAuthClientMetadata {
122 pub client_id: String,
123 pub client_name: Option<String>,
124 pub client_uri: Option<String>,
125 pub logo_uri: Option<String>,
126 pub redirect_uris: Vec<String>,
127 pub grant_types: Option<Vec<String>>,
128 pub response_types: Option<Vec<String>>,
129 pub scope: Option<String>,
130 pub token_endpoint_auth_method: Option<String>,
131 pub dpop_bound_access_tokens: Option<bool>,
132 pub jwks: Option<JsonValue>,
133 pub jwks_uri: Option<String>,
134 pub application_type: Option<String>,
135}
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct ProtectedResourceMetadata {
138 pub resource: String,
139 pub authorization_servers: Vec<String>,
140 pub bearer_methods_supported: Vec<String>,
141 pub scopes_supported: Vec<String>,
142 pub resource_documentation: Option<String>,
143}
144#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct AuthorizationServerMetadata {
146 pub issuer: String,
147 pub authorization_endpoint: String,
148 pub token_endpoint: String,
149 pub jwks_uri: String,
150 pub registration_endpoint: Option<String>,
151 pub scopes_supported: Option<Vec<String>>,
152 pub response_types_supported: Vec<String>,
153 pub response_modes_supported: Option<Vec<String>>,
154 pub grant_types_supported: Option<Vec<String>>,
155 pub token_endpoint_auth_methods_supported: Option<Vec<String>>,
156 pub code_challenge_methods_supported: Option<Vec<String>>,
157 pub pushed_authorization_request_endpoint: Option<String>,
158 pub require_pushed_authorization_requests: Option<bool>,
159 pub dpop_signing_alg_values_supported: Option<Vec<String>>,
160 pub authorization_response_iss_parameter_supported: Option<bool>,
161}
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct ParResponse {
164 pub request_uri: String,
165 pub expires_in: u64,
166}
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct TokenResponse {
169 pub access_token: String,
170 pub token_type: String,
171 pub expires_in: u64,
172 #[serde(skip_serializing_if = "Option::is_none")]
173 pub refresh_token: Option<String>,
174 #[serde(skip_serializing_if = "Option::is_none")]
175 pub scope: Option<String>,
176 #[serde(skip_serializing_if = "Option::is_none")]
177 pub sub: Option<String>,
178}
179#[derive(Debug, Clone, Serialize, Deserialize)]
180pub struct TokenRequest {
181 pub grant_type: String,
182 pub code: Option<String>,
183 pub redirect_uri: Option<String>,
184 pub code_verifier: Option<String>,
185 pub refresh_token: Option<String>,
186 pub client_id: Option<String>,
187 pub client_secret: Option<String>,
188}
189#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct DPoPClaims {
191 pub jti: String,
192 pub htm: String,
193 pub htu: String,
194 pub iat: i64,
195 #[serde(skip_serializing_if = "Option::is_none")]
196 pub ath: Option<String>,
197 #[serde(skip_serializing_if = "Option::is_none")]
198 pub nonce: Option<String>,
199}
200#[derive(Debug, Clone, Serialize, Deserialize)]
201pub struct JwkPublicKey {
202 pub kty: String,
203 pub crv: Option<String>,
204 pub x: Option<String>,
205 pub y: Option<String>,
206 #[serde(rename = "use")]
207 pub key_use: Option<String>,
208 pub kid: Option<String>,
209 pub alg: Option<String>,
210}
211#[derive(Debug, Clone, Serialize, Deserialize)]
212pub struct Jwks {
213 pub keys: Vec<JwkPublicKey>,
214}