Skip to main content

slim_config/
auth.rs

1// Copyright AGNTCY Contributors (https://github.com/agntcy)
2// SPDX-License-Identifier: Apache-2.0
3
4pub 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 slim_auth::errors::AuthError as SlimAuthError;
16
17use thiserror::Error;
18
19#[derive(Error, Debug)]
20pub enum ConfigAuthError {
21    // Configuration
22    #[error("username cannot be empty")]
23    AuthBasicEmptyUsername,
24    #[error("password cannot be empty")]
25    AuthBasicEmptyPassword,
26
27    #[error("client id cannot be empty")]
28    AuthOidcEmptyClientId,
29    #[error("client secret cannot be empty")]
30    AuthOidcEmptyClientSecret,
31
32    // App auth validation
33    #[error("auth.secret cannot be empty for shared_secret")]
34    AuthSecretEmpty,
35    #[error("auth.socket_path must be set for spire")]
36    AuthSpireSocketPathMissing,
37
38    // Propagated auth library errors
39    #[error("internal auth error")]
40    AuthInternalError(#[from] SlimAuthError),
41
42    // Verifier errors
43    #[error("audience required")]
44    AuthJwtAudienceRequired,
45
46    // Identity config errors
47    #[error("no identity provider configured")]
48    IdentityProviderNotConfigured,
49    #[error("no identity verifier configured")]
50    IdentityVerifierNotConfigured,
51}
52
53pub trait ClientAuthenticator {
54    // associated types
55    type ClientLayer;
56
57    fn get_client_layer(&self) -> Result<Self::ClientLayer, ConfigAuthError>;
58}
59
60pub trait ServerAuthenticator<Response: Default> {
61    // associated types
62    type ServerLayer;
63
64    fn get_server_layer(&self) -> Result<Self::ServerLayer, ConfigAuthError>;
65}