2026-07-16 12:32:17 +07:00
|
|
|
//! Pure OAuth entities — no HTTP or persistence logic.
|
2026-07-19 17:05:27 +07:00
|
|
|
//!
|
|
|
|
|
//! # Components
|
|
|
|
|
//!
|
|
|
|
|
//! - [`OAuthToken`] — access token with optional refresh token, epoch expiry
|
|
|
|
|
//! - [`OAuthConfig`] — provider configuration (auth URL, token URL, client id,
|
|
|
|
|
//! optional client secret, scopes)
|
2026-07-16 12:32:17 +07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
/// An OAuth 2.0 access token with optional refresh token and absolute
|
|
|
|
|
/// expiry time (epoch seconds).
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct OAuthToken {
|
2026-07-19 17:05:27 +07:00
|
|
|
/// The OAuth 2.0 access token string.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub access_token: String,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Optional refresh token for long-lived access.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub refresh_token: Option<String>,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Absolute expiry timestamp (epoch seconds since UNIX_EPOCH).
|
2026-07-16 12:32:17 +07:00
|
|
|
pub expires_at: u64,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Token type, e.g. `"Bearer"`.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub token_type: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Static configuration for an OAuth provider.
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct OAuthConfig {
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Authorization endpoint URL.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub auth_url: String,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Token exchange endpoint URL.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub token_url: String,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// OAuth client identifier.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub client_id: String,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Optional client secret (not all flows require it).
|
2026-07-16 12:32:17 +07:00
|
|
|
pub client_secret: Option<String>,
|
2026-07-19 17:05:27 +07:00
|
|
|
/// Space-separated list of requested scopes.
|
2026-07-16 12:32:17 +07:00
|
|
|
pub scopes: Vec<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for OAuthConfig {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
OAuthConfig {
|
|
|
|
|
auth_url: String::new(),
|
|
|
|
|
token_url: String::new(),
|
|
|
|
|
client_id: String::new(),
|
|
|
|
|
client_secret: None,
|
|
|
|
|
scopes: vec![
|
|
|
|
|
"openid".to_string(),
|
|
|
|
|
"profile".to_string(),
|
|
|
|
|
"email".to_string(),
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|