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