summaryrefslogtreecommitdiff
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 90ce4a5..a621756 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -1,3 +1,5 @@
+use axum::{extract::FromRequestParts, http::{StatusCode, request::Parts}};
+use serde::Serialize;
use argon2::{Argon2, PasswordHash, PasswordVerifier, password_hash::{
Error, PasswordHasher, SaltString, rand_core::OsRng
}};
@@ -14,6 +16,29 @@ pub fn check_password(password: &str, password_hash: &str) -> Result<bool, Error
Ok(argon2.verify_password(password.as_bytes(), &hash).is_ok())
}
+#[derive(Serialize)]
+pub struct Claims {
+ pub sub: String,
+ pub exp: usize,
+ pub iat: usize,
+ pub is_admin: bool,
+}
+
+//pub fn create_jwt(email: &str, is_admin: bool) -> Result
+
+pub struct AuthUser(pub Claims);
+
+impl<S: Send + Sync> FromRequestParts<S> for AuthUser {
+ type Rejection = StatusCode;
+
+ async fn from_request_parts(
+ parts: &mut Parts,
+ state: &S,
+ ) -> Result<Self, Self::Rejection> {
+ todo!();
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;