1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01:00
actix-extras/actix-web-httpauth/examples/middleware.rs

25 lines
691 B
Rust
Raw Normal View History

2022-09-11 22:55:40 +02:00
use actix_web::{dev::ServiceRequest, middleware, web, App, Error, HttpServer};
use actix_web_httpauth::{extractors::basic::BasicAuth, middleware::HttpAuthentication};
async fn validator(
req: ServiceRequest,
_credentials: BasicAuth,
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
2020-01-06 17:00:43 +01:00
Ok(req)
}
#[actix_web::main]
2020-01-06 17:00:43 +01:00
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
let auth = HttpAuthentication::basic(validator);
App::new()
.wrap(middleware::Logger::default())
.wrap(auth)
2020-01-06 17:00:43 +01:00
.service(web::resource("/").to(|| async { "Test\r\n" }))
})
.bind("127.0.0.1:8080")?
.workers(1)
.run()
2020-01-06 17:00:43 +01:00
.await
}