auth0_integration/
config.rs1use crate::error::AppError;
2use std::env;
3
4#[derive(Debug, Clone)]
5pub struct Auth0Config {
6 pub auth0_domain: String,
7 pub auth0_audience: String,
8 pub auth0_client_id: String,
9 pub auth0_client_secret: String,
10}
11
12impl Auth0Config {
13 pub fn from_env() -> Result<Self, AppError> {
14 Ok(Self {
15 auth0_domain: require_env("AUTH0_DOMAIN")?,
16 auth0_audience: require_env("AUTH0_AUDIENCE")?,
17 auth0_client_id: require_env("AUTH0_CLIENT_ID")?,
18 auth0_client_secret: require_env("AUTH0_CLIENT_SECRET")?,
19 })
20 }
21
22 pub fn auth0_issuer(&self) -> String {
23 format!("https://{}/", self.auth0_domain)
24 }
25
26 pub fn auth0_jwks_uri(&self) -> String {
27 format!("https://{}/.well-known/jwks.json", self.auth0_domain)
28 }
29
30 pub fn auth0_token_url(&self) -> String {
31 format!("https://{}/oauth/token", self.auth0_domain)
32 }
33}
34
35fn require_env(key: &str) -> Result<String, AppError> {
36 env::var(key).map_err(|_| AppError::Config(format!("Missing required env var: {key}")))
37}