feat: axum type 0.7

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-10-31 22:03:48 +01:00
parent 54fb0292f7
commit 522a1b525f
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
6 changed files with 191 additions and 44 deletions

196
Cargo.lock generated
View File

@ -391,6 +391,40 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.16"
source = "git+https://github.com/tokio-rs/axum?branch=main#276aa9e4b013de1646ea57cfcbf74e5966524f68"
dependencies = [
"async-trait",
"axum-core 0.3.4 (git+https://github.com/tokio-rs/axum?branch=main)",
"axum-macros 0.3.7",
"bytes",
"futures-util",
"http",
"http-body 0.4.5",
"hyper 0.14.27",
"hyper 1.0.0-rc.4",
"hyper-util",
"itoa",
"matchit",
"memchr",
"mime",
"percent-encoding",
"pin-project-lite",
"rustversion",
"serde",
"serde_json",
"serde_path_to_error",
"serde_urlencoded",
"sync_wrapper",
"tokio",
"tower",
"tower-hyper-http-body-compat",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum"
version = "0.6.20"
@ -398,15 +432,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
dependencies = [
"async-trait",
"axum-core",
"axum-macros",
"axum-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"axum-macros 0.3.8",
"bitflags 1.3.2",
"bytes",
"futures-util",
"headers",
"http",
"http-body",
"hyper",
"http-body 0.4.5",
"hyper 0.14.27",
"itoa",
"matchit",
"memchr",
@ -435,26 +469,65 @@ dependencies = [
"bytes",
"futures-util",
"http",
"http-body",
"http-body 0.4.5",
"mime",
"rustversion",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-core"
version = "0.3.4"
source = "git+https://github.com/tokio-rs/axum?branch=main#276aa9e4b013de1646ea57cfcbf74e5966524f68"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http",
"http-body 0.4.5",
"mime",
"pin-project-lite",
"rustversion",
"sync_wrapper",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-extra"
version = "0.7.4"
source = "git+https://github.com/tokio-rs/axum?branch=main#d7258bf009194cf2f242694e673759d1dbf8cfc0"
dependencies = [
"axum 0.6.16",
"axum-core 0.3.4 (git+https://github.com/tokio-rs/axum?branch=main)",
"bytes",
"cookie",
"futures-util",
"headers",
"http",
"http-body 0.4.5",
"mime",
"pin-project-lite",
"serde",
"tower",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-extra"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a93e433be9382c737320af3924f7d5fc6f89c155cf2bf88949d8f5126fab283f"
dependencies = [
"axum",
"axum-core",
"axum 0.6.20",
"axum-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes",
"cookie",
"futures-util",
"http",
"http-body",
"http-body 0.4.5",
"mime",
"pin-project-lite",
"serde",
@ -470,12 +543,12 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ab90e7b70bea63a153137162affb6a0bce26b584c24a4c7885509783e2cf30b"
dependencies = [
"axum",
"axum-core",
"axum 0.6.20",
"axum-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes",
"futures-util",
"http",
"http-body",
"http-body 0.4.5",
"mime",
"pin-project-lite",
"serde",
@ -485,6 +558,17 @@ dependencies = [
"tower-service",
]
[[package]]
name = "axum-macros"
version = "0.3.7"
source = "git+https://github.com/tokio-rs/axum?branch=main#276aa9e4b013de1646ea57cfcbf74e5966524f68"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]]
name = "axum-macros"
version = "0.3.8"
@ -504,10 +588,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "714cad544cd87d8da821cda715bb9aaa5d4d1adbdb64c549b18138e3cbf93c44"
dependencies = [
"async-session",
"axum",
"axum 0.6.20",
"axum-extra 0.7.7",
"futures",
"http-body",
"http-body 0.4.5",
"tokio",
"tower",
"tracing",
@ -566,7 +650,7 @@ name = "basic"
version = "0.1.0"
dependencies = [
"anyhow",
"axum",
"axum 0.6.16",
"clap 4.4.6",
"nefarious-login",
"tokio",
@ -712,7 +796,7 @@ name = "clap"
version = "0.1.0"
dependencies = [
"anyhow",
"axum",
"axum 0.6.16",
"clap 4.4.6",
"nefarious-login",
"tokio",
@ -1598,6 +1682,16 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-body"
version = "1.0.0-rc.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "951dfc2e32ac02d67c90c0d65bd27009a635dc9b381a2cc7d284ab01e3a0150d"
dependencies = [
"bytes",
"http",
]
[[package]]
name = "http-range-header"
version = "0.3.1"
@ -1628,7 +1722,7 @@ dependencies = [
"futures-util",
"h2",
"http",
"http-body",
"http-body 0.4.5",
"httparse",
"httpdate",
"itoa",
@ -1640,6 +1734,27 @@ dependencies = [
"want",
]
[[package]]
name = "hyper"
version = "1.0.0-rc.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d280a71f348bcc670fc55b02b63c53a04ac0bf2daff2980795aeaf53edae10e6"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"h2",
"http",
"http-body 1.0.0-rc.2",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"tokio",
"tracing",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.24.1"
@ -1648,12 +1763,32 @@ checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97"
dependencies = [
"futures-util",
"http",
"hyper",
"hyper 0.14.27",
"rustls 0.21.7",
"tokio",
"tokio-rustls 0.24.1",
]
[[package]]
name = "hyper-util"
version = "0.0.0"
source = "git+https://github.com/hyperium/hyper-util?rev=d97181a#d97181a278d9c59f1d7f2713732e400440861216"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http",
"http-body 1.0.0-rc.2",
"hyper 1.0.0-rc.4",
"once_cell",
"pin-project-lite",
"socket2 0.5.5",
"tokio",
"tower",
"tower-service",
"tracing",
]
[[package]]
name = "iana-time-zone"
version = "0.1.58"
@ -1946,8 +2081,8 @@ dependencies = [
"anyhow",
"async-sqlx-session",
"async-trait",
"axum",
"axum-extra 0.7.7",
"axum 0.6.16",
"axum-extra 0.7.4",
"axum-sessions",
"clap 4.4.6",
"oauth2",
@ -2579,8 +2714,8 @@ dependencies = [
"futures-util",
"h2",
"http",
"http-body",
"hyper",
"http-body 0.4.5",
"hyper 0.14.27",
"hyper-rustls",
"ipnet",
"js-sys",
@ -3577,7 +3712,7 @@ dependencies = [
"futures-core",
"futures-util",
"http",
"http-body",
"http-body 0.4.5",
"http-range-header",
"pin-project-lite",
"tower-layer",
@ -3585,6 +3720,21 @@ dependencies = [
"tracing",
]
[[package]]
name = "tower-hyper-http-body-compat"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7ea3e622710ee44a8255baa6fcb2a34d67450e2ffb48e5e58d5a7bd6ff55a21"
dependencies = [
"http",
"http-body 0.4.5",
"http-body 1.0.0-rc.2",
"hyper 1.0.0-rc.4",
"pin-project-lite",
"tower",
"tower-service",
]
[[package]]
name = "tower-layer"
version = "0.3.2"
@ -4040,7 +4190,7 @@ version = "3.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aab76990d831d980e72e52f6eed5ef8e4a740ee7ad14c65e1a3374b974f92258"
dependencies = [
"axum",
"axum 0.6.20",
"axum-extra 0.8.0",
"base64-compat",
"custom_error",

View File

@ -13,8 +13,8 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
clap = {version = "4.3.0", features = ["derive", "env"]}
async-trait = {version = "0.1.68", features = []}
axum = {version = "0.6.18", features = []}
axum-extra = {version = "0.7.4", features = ["cookie", "cookie-private"]}
axum = { git = "https://github.com/tokio-rs/axum", branch = "main", features = ["macros"] }
axum-extra = {git = "https://github.com/tokio-rs/axum", branch = "main" , features = ["cookie", "cookie-private", "typed-header"]}
axum-sessions = {version = "0.5.0", features = []}
async-sqlx-session = {version = "0.4.0", features = ["pg"]}

View File

@ -26,4 +26,4 @@ openidconnect.workspace = true
[dev-dependencies]
tokio.workspace = true
pretty_assertions.workspace = true
sealed_test.workspace = true
sealed_test.workspace = true

View File

@ -1,16 +1,15 @@
use std::fmt::Display;
use axum::extract::{FromRef, FromRequestParts, Query, State};
use axum::headers::authorization::Basic;
use axum::headers::{Authorization, Cookie};
use axum::http::request::Parts;
use axum::http::StatusCode;
use axum::response::{ErrorResponse, IntoResponse, Redirect};
use axum::routing::get;
use axum::{async_trait, Json, RequestPartsExt, Router, TypedHeader};
use axum::{async_trait, Json, RequestPartsExt, Router};
use axum_extra::headers::authorization::Basic;
use axum_extra::headers::{Authorization, Cookie};
use axum_extra::TypedHeader;
use serde::Deserialize;
use serde_json::json;

View File

@ -1,4 +1,4 @@
use std::net::SocketAddr;
use std::{net::SocketAddr, str::FromStr};
use axum::{
extract::{FromRef, State},
@ -58,13 +58,10 @@ async fn main() -> anyhow::Result<()> {
.with_state(state)
.nest("/auth", AuthController::new_router(auth_service).await?);
let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
println!("listening on: {addr}");
println!("open browser at: http://localhost:3001/auth/zitadel");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
let addr = SocketAddr::from_str(&format!("{}:{}", "127.0.0.1", "3000"))?;
let listener = tokio::net::TcpListener::bind(&addr).await?;
axum::serve(listener, app).await?;
Ok(())
}

View File

@ -1,4 +1,4 @@
use std::net::SocketAddr;
use std::{net::SocketAddr, str::FromStr};
use axum::{
extract::{FromRef, State},
@ -57,10 +57,11 @@ async fn main() -> anyhow::Result<()> {
let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
println!("listening on: {addr}");
println!("open browser at: http://localhost:3001/auth/zitadel");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
let addr = SocketAddr::from_str(&format!("{}:{}", "127.0.0.1", "3000"))?;
let listener = tokio::net::TcpListener::bind(&addr).await?;
axum::serve(listener, app).await?;
Ok(())
}