mirror of
https://github.com/pfzetto/axum-negotiate
synced 2025-12-07 16:35:23 +01:00
Initial Commit
Initial implementation of RFC4559 for axum.
This commit is contained in:
commit
b839d892c5
6 changed files with 1009 additions and 0 deletions
31
examples/basic.rs
Normal file
31
examples/basic.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use axum::{error_handling::HandleErrorLayer, response::IntoResponse, routing::get, Router};
|
||||
use axum_negotiate::{NegotiateAuthLayer, Upn};
|
||||
use log::warn;
|
||||
use tokio::net::TcpListener;
|
||||
use tower::ServiceBuilder;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let spn = "HTTP/webserver.example.com";
|
||||
|
||||
let auth_service = ServiceBuilder::new()
|
||||
.layer(HandleErrorLayer::new(|e: axum_negotiate::Error| async {
|
||||
warn!("{}", e);
|
||||
e.into_response()
|
||||
}))
|
||||
.layer(NegotiateAuthLayer::new(spn.to_owned()).unwrap());
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(hello_world))
|
||||
.route_layer(auth_service);
|
||||
|
||||
let listener = TcpListener::bind("[::]:8080").await.unwrap();
|
||||
|
||||
axum::serve(listener, app).await.unwrap()
|
||||
}
|
||||
|
||||
async fn hello_world(Upn(upn): Upn) -> impl IntoResponse {
|
||||
format!("Hello {}", upn)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue