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 pub controller_did: Option<String>, 111} 112 113#[derive(Debug, Clone)] 114pub struct DeviceData { 115 pub session_id: String, 116 pub user_agent: Option<String>, 117 pub ip_address: String, 118 pub last_seen_at: DateTime<Utc>, 119} 120 121#[derive(Debug, Clone)] 122pub struct TokenData { 123 pub did: String, 124 pub token_id: String, 125 pub created_at: DateTime<Utc>, 126 pub updated_at: DateTime<Utc>, 127 pub expires_at: DateTime<Utc>, 128 pub client_id: String, 129 pub client_auth: ClientAuth, 130 pub device_id: Option<String>, 131 pub parameters: AuthorizationRequestParameters, 132 pub details: Option<JsonValue>, 133 pub code: Option<String>, 134 pub current_refresh_token: Option<String>, 135 pub scope: Option<String>, 136 pub controller_did: Option<String>, 137} 138 139#[derive(Debug, Clone, Serialize, Deserialize)] 140pub struct AuthorizedClientData { 141 pub scope: Option<String>, 142 pub remember: bool, 143} 144 145#[derive(Debug, Clone, Serialize, Deserialize)] 146pub struct OAuthClientMetadata { 147 pub client_id: String, 148 pub client_name: Option<String>, 149 pub client_uri: Option<String>, 150 pub logo_uri: Option<String>, 151 pub redirect_uris: Vec<String>, 152 pub grant_types: Option<Vec<String>>, 153 pub response_types: Option<Vec<String>>, 154 pub scope: Option<String>, 155 pub token_endpoint_auth_method: Option<String>, 156 pub dpop_bound_access_tokens: Option<bool>, 157 pub jwks: Option<JsonValue>, 158 pub jwks_uri: Option<String>, 159 pub application_type: Option<String>, 160} 161 162#[derive(Debug, Clone, Serialize, Deserialize)] 163pub struct ProtectedResourceMetadata { 164 pub resource: String, 165 pub authorization_servers: Vec<String>, 166 pub bearer_methods_supported: Vec<String>, 167 pub scopes_supported: Vec<String>, 168 pub resource_documentation: Option<String>, 169} 170 171#[derive(Debug, Clone, Serialize, Deserialize)] 172pub struct AuthorizationServerMetadata { 173 pub issuer: String, 174 pub authorization_endpoint: String, 175 pub token_endpoint: String, 176 pub jwks_uri: String, 177 pub registration_endpoint: Option<String>, 178 pub scopes_supported: Option<Vec<String>>, 179 pub response_types_supported: Vec<String>, 180 pub response_modes_supported: Option<Vec<String>>, 181 pub grant_types_supported: Option<Vec<String>>, 182 pub token_endpoint_auth_methods_supported: Option<Vec<String>>, 183 pub code_challenge_methods_supported: Option<Vec<String>>, 184 pub pushed_authorization_request_endpoint: Option<String>, 185 pub require_pushed_authorization_requests: Option<bool>, 186 pub dpop_signing_alg_values_supported: Option<Vec<String>>, 187 pub authorization_response_iss_parameter_supported: Option<bool>, 188} 189 190#[derive(Debug, Clone, Serialize, Deserialize)] 191pub struct ParResponse { 192 pub request_uri: String, 193 pub expires_in: u64, 194} 195 196#[derive(Debug, Clone, Serialize, Deserialize)] 197pub struct TokenResponse { 198 pub access_token: String, 199 pub token_type: String, 200 pub expires_in: u64, 201 #[serde(skip_serializing_if = "Option::is_none")] 202 pub refresh_token: Option<String>, 203 #[serde(skip_serializing_if = "Option::is_none")] 204 pub scope: Option<String>, 205 #[serde(skip_serializing_if = "Option::is_none")] 206 pub sub: Option<String>, 207} 208 209#[derive(Debug, Clone, Serialize, Deserialize)] 210pub struct TokenRequest { 211 pub grant_type: String, 212 pub code: Option<String>, 213 pub redirect_uri: Option<String>, 214 pub code_verifier: Option<String>, 215 pub refresh_token: Option<String>, 216 pub client_id: Option<String>, 217 pub client_secret: Option<String>, 218} 219 220#[derive(Debug, Clone, Serialize, Deserialize)] 221pub struct DPoPClaims { 222 pub jti: String, 223 pub htm: String, 224 pub htu: String, 225 pub iat: i64, 226 #[serde(skip_serializing_if = "Option::is_none")] 227 pub ath: Option<String>, 228 #[serde(skip_serializing_if = "Option::is_none")] 229 pub nonce: Option<String>, 230} 231 232#[derive(Debug, Clone, Serialize, Deserialize)] 233pub struct JwkPublicKey { 234 pub kty: String, 235 pub crv: Option<String>, 236 pub x: Option<String>, 237 pub y: Option<String>, 238 #[serde(rename = "use")] 239 pub key_use: Option<String>, 240 pub kid: Option<String>, 241 pub alg: Option<String>, 242} 243 244#[derive(Debug, Clone, Serialize, Deserialize)] 245pub struct Jwks { 246 pub keys: Vec<JwkPublicKey>, 247}