1pub mod app_auth;
5pub mod basic;
6pub mod identity;
7pub mod jwt;
8pub mod oidc;
9#[cfg(not(target_family = "windows"))]
10pub mod spire;
11pub mod static_jwt;
12
13pub use app_auth::AuthConfig;
14
15use std::path::PathBuf;
16
17use schemars::JsonSchema;
18use serde::{Deserialize, Serialize};
19
20#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
37#[serde(rename_all = "snake_case")]
38pub enum PolicyConfig {
39 Rego(String),
42 RegoFile(PathBuf),
44 Cel(String),
47}
48
49use slim_auth::errors::AuthError as SlimAuthError;
50
51use thiserror::Error;
52
53#[derive(Error, Debug)]
54pub enum ConfigAuthError {
55 #[error("username cannot be empty")]
57 AuthBasicEmptyUsername,
58 #[error("password cannot be empty")]
59 AuthBasicEmptyPassword,
60
61 #[error("client id cannot be empty")]
62 AuthOidcEmptyClientId,
63 #[error("client secret cannot be empty")]
64 AuthOidcEmptyClientSecret,
65
66 #[error("auth.secret cannot be empty for shared_secret")]
68 AuthSecretEmpty,
69 #[error("auth.socket_path must be set for spire")]
70 AuthSpireSocketPathMissing,
71
72 #[error("internal auth error")]
74 AuthInternalError(#[from] SlimAuthError),
75
76 #[error("audience required")]
78 AuthJwtAudienceRequired,
79
80 #[error("no identity provider configured")]
82 IdentityProviderNotConfigured,
83 #[error("no identity verifier configured")]
84 IdentityVerifierNotConfigured,
85}
86
87pub trait ClientAuthenticator {
88 type ClientLayer;
90
91 fn get_client_layer(&self) -> Result<Self::ClientLayer, ConfigAuthError>;
92}
93
94pub trait ServerAuthenticator<Response: Default> {
95 type ServerLayer;
97
98 fn get_server_layer(&self) -> Result<Self::ServerLayer, ConfigAuthError>;
99}