use std::time::{Duration, Instant};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub enum AuthTokens {
Cst {
cst: String,
x_security_token: String,
},
OAuth {
access_token: String,
refresh_token: String,
token_type: String,
expires_at: Instant,
},
}
impl AuthTokens {
pub fn needs_refresh(&self, skew: Duration) -> bool {
match self {
Self::Cst { .. } => false,
Self::OAuth { expires_at, .. } => Instant::now() + skew >= *expires_at,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) struct OAuthPayload {
pub access_token: String,
pub refresh_token: String,
pub token_type: String,
pub expires_in: String,
}
#[derive(Debug, Clone, Default)]
pub struct SessionState {
pub tokens: Option<AuthTokens>,
pub account_id: Option<String>,
pub client_id: Option<String>,
pub lightstreamer_endpoint: Option<String>,
}