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