use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use crate::error::Error;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthTokens {
pub access_token: String,
pub refresh_token: Option<String>,
pub expires_in: Option<i64>,
pub token_type: String,
pub id_token: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OAuthUserInfo {
pub provider: String,
pub provider_user_id: String,
pub email: Option<String>,
pub email_verified: bool,
pub name: Option<String>,
pub picture: Option<String>,
pub raw: serde_json::Value,
}
#[async_trait]
pub trait OAuthProvider: Send + Sync {
fn name(&self) -> &str;
fn authorization_url(&self, state: &str, scopes: &[String]) -> String;
async fn exchange_code(&self, code: &str) -> Result<OAuthTokens, Error>;
async fn get_user_info(&self, access_token: &str) -> Result<OAuthUserInfo, Error>;
async fn refresh_token(&self, refresh_token: &str) -> Result<OAuthTokens, Error>;
}