Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/update axum 0.7.x #518

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ rocket = ["credentials", "oidc", "dep:rocket"]

[dependencies]
async-trait = { version = "0.1.74", optional = true }
axum = { version = "0.6.20", optional = true, features = ["headers", "macros"] }
axum-extra = { version = "0.8.0", optional = true }
axum = { version = "0.7.3", optional = true, features = ["macros"] }
axum-extra = { version = "0.9.1", optional = true, features = ["typed-header"] }
base64-compat = { version = "1", optional = true }
custom_error = "1.9.2"
document-features = { version = "0.2", optional = true }
11 changes: 6 additions & 5 deletions examples/axum_webapi_oauth_interception_basic.rs
Original file line number Diff line number Diff line change
@@ -3,8 +3,11 @@ use std::net::SocketAddr;
use axum::response::IntoResponse;
use axum::routing::get;
use axum::Router;
use tokio::net::TcpListener;
use zitadel::axum::introspection::{IntrospectedUser, IntrospectionStateBuilder};

// Run example with cargo run --example <file name> -F axum to activate the axum feature

async fn unauthed() -> String {
"Hello Unauthorized User".into()
}
@@ -34,11 +37,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.with_state(is);

let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
println!("listening on: {addr}");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
println!("listening on: {addr}, go to http://localhost:3001/authed or /unauthed");
let listener = TcpListener::bind(addr).await?;
axum::serve(listener, app.into_make_service()).await?;

Ok(())
}
10 changes: 6 additions & 4 deletions src/axum/introspection/user.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use axum::{
async_trait,
extract::{FromRef, FromRequestParts},
headers::{authorization::Bearer, Authorization},
http::request::Parts,
http::{request::Parts, StatusCode},
response::IntoResponse,
Json, RequestPartsExt, TypedHeader,
Json, RequestPartsExt,
};
use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use custom_error::custom_error;
use openidconnect::TokenIntrospectionResponse;
use reqwest::StatusCode;
use serde_json::json;

use crate::oidc::introspection::{introspect, IntrospectionError, ZitadelIntrospectionResponse};
Loading