mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-22 21:51:35 +08:00
24 lines
839 B
Rust
24 lines
839 B
Rust
use crate::auth::apikey::ApiKeyAuth;
|
|
use crate::auth::basic::BasicAuth;
|
|
use crate::auth::forward::ForwardAuth;
|
|
use crate::auth::jwt::JwtAuth;
|
|
use crate::utils::types::InnerAuth;
|
|
use pingora_proxy::Session;
|
|
|
|
#[async_trait::async_trait]
|
|
pub trait AuthValidator {
|
|
async fn validate(&self, session: &mut Session) -> bool;
|
|
}
|
|
pub async fn authenticate(auth: &InnerAuth, session: &mut Session) -> bool {
|
|
match &*auth.auth_type {
|
|
"basic" => BasicAuth(&auth.auth_cred).validate(session).await,
|
|
"apikey" => ApiKeyAuth(&auth.auth_cred).validate(session).await,
|
|
"jwt" => JwtAuth().validate(session).await,
|
|
"forward" => ForwardAuth(&auth.auth_cred).validate(session).await,
|
|
_ => {
|
|
log::warn!("Unsupported authentication mechanism : {}", &*auth.auth_type);
|
|
false
|
|
}
|
|
}
|
|
}
|