Skip to content

Commit 8c51b37

Browse files
authored
feat: update general dependencies and axum to v0.7 (#521)
* feat: update general dependencies and axum to v0.7 Closes #514. Closes #519. Closes #518. * ignore marvin attack for now. there is no fix * fix doctest
1 parent a94b889 commit 8c51b37

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-30
lines changed

.github/workflows/security-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
- uses: rustsec/[email protected]
1717
with:
1818
token: ${{ secrets.GITHUB_TOKEN }}
19-
ignore: RUSTSEC-2020-0071
19+
ignore: RUSTSEC-2020-0071, RUSTSEC-2023-0071

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,35 @@ rocket = ["credentials", "oidc", "dep:rocket"]
5353

5454
[dependencies]
5555
async-trait = { version = "0.1.74", optional = true }
56-
axum = { version = "0.6.20", optional = true, features = ["headers", "macros"] }
57-
axum-extra = { version = "0.8.0", optional = true }
56+
axum = { version = "0.7", optional = true, features = ["macros"] }
57+
axum-extra = { version = "0.9", optional = true, features = ["typed-header"] }
5858
base64-compat = { version = "1", optional = true }
5959
custom_error = "1.9.2"
6060
document-features = { version = "0.2", optional = true }
61-
jsonwebtoken = { version = "9.1.0", optional = true }
61+
jsonwebtoken = { version = "9.2.0", optional = true }
6262
openidconnect = { version = "3.4.0", optional = true }
63-
pbjson-types = { version = "0.5.1", optional = true }
64-
prost = { version = "0.11", optional = true }
65-
prost-types = { version = "0.11", optional = true }
66-
reqwest = { version = "0.11.22", features = ["json", "rustls-tls"], default-features = false, optional = true }
67-
rocket = { version = "0.5.0-rc.3", optional = true }
63+
pbjson-types = { version = "0.6", optional = true }
64+
prost = { version = "0.12", optional = true }
65+
prost-types = { version = "0.12", optional = true }
66+
reqwest = { version = "0.11.23", features = ["json", "rustls-tls"], default-features = false, optional = true }
67+
rocket = { version = "0.5.0", optional = true }
6868
serde = { version = "1.0", features = ["derive"], optional = true }
6969
serde_json = { version = "1.0", optional = true }
7070
serde_urlencoded = { version = "0.7.1", optional = true }
71-
time = { version = "0.3.30", optional = true }
71+
time = { version = "0.3.31", optional = true }
7272
tokio = { version = "1", optional = true, features = [
7373
"macros",
7474
"rt-multi-thread",
7575
] }
76-
tonic = { version = "0.9", features = [
76+
tonic = { version = "0.10", features = [
7777
"tls",
7878
"tls-roots",
7979
"tls-roots-common",
8080
], optional = true }
81-
tonic-types = { version = "0.9", optional = true }
81+
tonic-types = { version = "0.10", optional = true }
8282

8383
[dev-dependencies]
84-
chrono = "0.4.31"
84+
chrono = "0.4.32"
8585
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
8686
tower = { version = "0.4.13" }
8787

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
This repository contains the gRPC service clients and helpers/credentials/other utilities
44
for [ZITADEL](https://github.com/zitadel/zitadel).
55

6+
The following features are present:
7+
- API clients for communication with the ZITADEL API (calling gRPC methods)
8+
- Credentials support for the API clients (access token and service account interceptors)
9+
- OIDC Introspection support for [rocket](https://rocket.rs)
10+
- OIDC Introspection support for [axum](https://github.com/tokio-rs/axum)
11+
612
### Example
713

814
There exist a few examples in the `examples` directory.
@@ -11,7 +17,7 @@ Go there to see the library in action, or head over to the
1117

1218
### Development
1319

14-
After you checkout the repository, you need ["just"](https://just.systems) to run
20+
After you clone the repository, you need ["just"](https://just.systems) to run
1521
certain tasks. Generating the gRPC clients is done via `just generate-grpc` or `just`
1622
(as it is configured to be the default action for just).
1723

examples/axum_webapi_oauth_interception_basic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::net::SocketAddr;
33
use axum::response::IntoResponse;
44
use axum::routing::get;
55
use axum::Router;
6+
use tokio::net::TcpListener;
67
use zitadel::axum::introspection::{IntrospectedUser, IntrospectionStateBuilder};
78

89
async fn unauthed() -> String {
@@ -35,8 +36,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3536

3637
let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
3738
println!("listening on: {addr}");
38-
axum::Server::bind(&addr)
39-
.serve(app.into_make_service())
39+
let listener = TcpListener::bind(addr).await?;
40+
axum::serve(listener, app.into_make_service())
4041
.await
4142
.unwrap();
4243

src/axum/introspection/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! # use axum::response::IntoResponse;
1515
//! # use axum::routing::get;
1616
//! # use axum::Router;
17+
//! # use tokio::net::TcpListener;
1718
//! # use tokio::runtime::Builder;
1819
//! # use std::net::SocketAddr;
1920
//! #
@@ -32,8 +33,8 @@
3233
//!
3334
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3001));
3435
//! println!("listening on: {addr}");
35-
//! axum::Server::bind(&addr)
36-
//! .serve(app.into_make_service())
36+
//! let listener = TcpListener::bind(addr).await.unwrap();
37+
//! axum::serve(listener, app.into_make_service())
3738
//! .await
3839
//! .unwrap();
3940
//! # }

src/axum/introspection/user.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
use axum::http::StatusCode;
12
use axum::{
23
async_trait,
34
extract::{FromRef, FromRequestParts},
4-
headers::{authorization::Bearer, Authorization},
55
http::request::Parts,
66
response::IntoResponse,
7-
Json, RequestPartsExt, TypedHeader,
7+
Json, RequestPartsExt,
88
};
9+
use axum_extra::headers::authorization::Bearer;
10+
use axum_extra::headers::Authorization;
11+
use axum_extra::TypedHeader;
912
use custom_error::custom_error;
1013
use openidconnect::TokenIntrospectionResponse;
11-
use reqwest::StatusCode;
1214
use serde_json::json;
1315

1416
use crate::oidc::introspection::{introspect, IntrospectionError, ZitadelIntrospectionResponse};
@@ -51,7 +53,7 @@ impl IntoResponse for IntrospectionGuardError {
5153
}
5254
}
5355

54-
/// struct for the extracted user. The extracted user will always be valid, when fetched in a
56+
/// Struct for the extracted user. The extracted user will always be valid, when fetched in a
5557
/// request function arguments. If not the api will return with an appropriate error.
5658
#[derive(Debug)]
5759
pub struct IntrospectedUser {
@@ -132,10 +134,10 @@ mod tests {
132134
use axum::routing::get;
133135
use axum::Router;
134136
use tokio::runtime::Builder;
137+
use tower::ServiceExt;
135138

136139
use crate::axum::introspection::{IntrospectionState, IntrospectionStateBuilder};
137140
use crate::credentials::Application;
138-
use tower::ServiceExt;
139141

140142
use super::*;
141143

src/rocket/introspection/guard.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@ impl<'request> FromRequest<'request> for &'request IntrospectedUser {
6060
async fn from_request(request: &'request Request<'_>) -> Outcome<Self, Self::Error> {
6161
let auth: Vec<_> = request.headers().get("authorization").collect();
6262
if auth.len() > 1 {
63-
return Outcome::Failure((Status::BadRequest, &IntrospectionGuardError::InvalidHeader));
63+
return Outcome::Error((Status::BadRequest, &IntrospectionGuardError::InvalidHeader));
6464
} else if auth.is_empty() {
65-
return Outcome::Failure((
66-
Status::Unauthorized,
67-
&IntrospectionGuardError::Unauthorized,
68-
));
65+
return Outcome::Error((Status::Unauthorized, &IntrospectionGuardError::Unauthorized));
6966
}
7067

7168
let token = auth[0];
7269
if !token.starts_with("Bearer ") {
73-
return Outcome::Failure((Status::Unauthorized, &IntrospectionGuardError::WrongScheme));
70+
return Outcome::Error((Status::Unauthorized, &IntrospectionGuardError::WrongScheme));
7471
}
7572

7673
let result = request
@@ -140,7 +137,7 @@ impl<'request> FromRequest<'request> for &'request IntrospectedUser {
140137

141138
match result {
142139
Ok(user) => Outcome::Success(user),
143-
Err((status, error)) => Outcome::Failure((*status, error)),
140+
Err((status, error)) => Outcome::Error((*status, error)),
144141
}
145142
}
146143
}

0 commit comments

Comments
 (0)