Added httpauth, looking into sessions
This commit is contained in:
@@ -1,3 +1,37 @@
|
||||
use actix_web::{dev::ServiceRequest, Error};
|
||||
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
||||
use siren::ServiceError;
|
||||
|
||||
pub struct User {
|
||||
pub id: i32
|
||||
pub id: i32,
|
||||
pub first_name: String,
|
||||
pub last_name: String,
|
||||
pub email: String
|
||||
}
|
||||
|
||||
// https://github.com/Sirneij/rust-auth/blob/main/backend/src/routes/users/login.rs
|
||||
// https://dev.to/sirneij/authentication-system-using-rust-actix-web-and-sveltekit-user-registration-580h
|
||||
// https://github.com/actix/actix-extras/blob/master/actix-session/examples/basic.rs
|
||||
// maybe https://github.com/actix/actix-extras/blob/master/actix-identity/examples/identity.rs
|
||||
|
||||
pub async fn validator(req: ServiceRequest, credentials: BearerAuth) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
||||
let token = credentials.token();
|
||||
println!("{:?}", req);
|
||||
match validate_token(token) {
|
||||
Ok(res) => {
|
||||
if res {
|
||||
Ok(req)
|
||||
} else {
|
||||
Err((Error::from(actix_web::error::ErrorUnauthorized("Invalid token")), req))
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
Err((Error::from(actix_web::error::ErrorUnauthorized(err)), req))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_token(token: &str) -> Result<bool, ServiceError> {
|
||||
println!("Validating token: {}", token);
|
||||
Ok(true)
|
||||
}
|
||||
Reference in New Issue
Block a user