aboutsummaryrefslogtreecommitdiff
path: root/src/modules/auth/basic.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-05-30 02:18:27 +0200
committermetamuffin <metamuffin@disroot.org>2024-05-30 02:18:27 +0200
commit2b64fc57bbed04dd8249afcbbc6ac6849e05ba36 (patch)
treedd5f22f70c2996d79399bef4eeeacd25c2d86c69 /src/modules/auth/basic.rs
parent8d58647a5edebe8eb37ee8d24f2ffc2c400a655c (diff)
downloadgnix-2b64fc57bbed04dd8249afcbbc6ac6849e05ba36.tar
gnix-2b64fc57bbed04dd8249afcbbc6ac6849e05ba36.tar.bz2
gnix-2b64fc57bbed04dd8249afcbbc6ac6849e05ba36.tar.zst
implment creds for http basic authv2.0.0
Diffstat (limited to 'src/modules/auth/basic.rs')
-rw-r--r--src/modules/auth/basic.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/modules/auth/basic.rs b/src/modules/auth/basic.rs
index 08870c4..9af5b01 100644
--- a/src/modules/auth/basic.rs
+++ b/src/modules/auth/basic.rs
@@ -13,7 +13,9 @@ use hyper::{
use log::debug;
use serde::Deserialize;
use serde_yaml::Value;
-use std::{collections::HashSet, pin::Pin, sync::Arc};
+use std::{pin::Pin, sync::Arc};
+
+use super::Credentials;
pub struct HttpBasicAuthKind;
impl NodeKind for HttpBasicAuthKind {
@@ -28,7 +30,7 @@ impl NodeKind for HttpBasicAuthKind {
#[derive(Deserialize)]
pub struct HttpBasicAuth {
realm: String,
- valid: HashSet<String>,
+ users: Credentials,
next: DynNode,
}
@@ -46,7 +48,8 @@ impl Node for HttpBasicAuth {
.ok_or(ServiceError::BadAuth)?;
let k = base64::engine::general_purpose::STANDARD.decode(k)?;
let k = String::from_utf8(k)?;
- if self.valid.contains(&k) {
+ let (username, password) = k.split_once(":").ok_or(ServiceError::BadAuth)?;
+ if self.users.authentificate(username, password) {
debug!("valid auth");
return self.next.handle(context, request).await;
} else {