use crate::error::AppError;
use std::env;
#[derive(Debug, Clone)]
pub struct Auth0Config {
pub auth0_domain: String,
pub auth0_audience: String,
pub auth0_client_id: String,
pub auth0_client_secret: String,
}
impl Auth0Config {
pub fn from_env() -> Result<Self, AppError> {
Ok(Self {
auth0_domain: require_env("AUTH0_DOMAIN")?,
auth0_audience: require_env("AUTH0_AUDIENCE")?,
auth0_client_id: require_env("AUTH0_CLIENT_ID")?,
auth0_client_secret: require_env("AUTH0_CLIENT_SECRET")?,
})
}
pub fn auth0_issuer(&self) -> String {
format!("https://{}/", self.auth0_domain)
}
pub fn auth0_jwks_uri(&self) -> String {
format!("https://{}/.well-known/jwks.json", self.auth0_domain)
}
pub fn auth0_token_url(&self) -> String {
format!("https://{}/oauth/token", self.auth0_domain)
}
}
fn require_env(key: &str) -> Result<String, AppError> {
env::var(key).map_err(|_| AppError::Config(format!("Missing required env var: {key}")))
}