Path level authentication

This commit is contained in:
Ara Sadoyan
2026-03-03 19:35:16 +01:00
parent 3afa2f209f
commit 9d986f9a28
7 changed files with 77 additions and 15 deletions

View File

@@ -57,22 +57,23 @@ fn validate(auth: &dyn AuthValidator, session: &Session) -> bool {
auth.validate(session)
}
pub fn authenticate(c: &[Arc<str>], session: &Session) -> bool {
match &*c[0] {
// pub fn authenticate(c: &[Arc<str>], session: &Session) -> bool {
pub fn authenticate(auth_type: &Arc<str>, credentials: &Arc<str>, session: &Session) -> bool {
match &*auth_type.clone() {
"basic" => {
let auth = BasicAuth(&*c[1]);
let auth = BasicAuth(&*credentials.clone());
validate(&auth, session)
}
"apikey" => {
let auth = ApiKeyAuth(&*c[1]);
let auth = ApiKeyAuth(&*credentials.clone());
validate(&auth, session)
}
"jwt" => {
let auth = JwtAuth(&*c[1]);
let auth = JwtAuth(&*credentials.clone());
validate(&auth, session)
}
_ => {
println!("Unsupported authentication mechanism : {}", c[0]);
println!("Unsupported authentication mechanism : {}", auth_type);
false
}
}