Skip to content

Commit

Permalink
Release 0.12.4
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Sep 4, 2023
1 parent d7e5561 commit d5e81b9
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 74 deletions.
2 changes: 1 addition & 1 deletion examples/actix-app/config/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ span = { "http.method" = "string", "http.target" = "string", "http.status_code"
app-name = "data-cube"

[openapi]
custom-html = "assets/docs/rapidoc.html"
custom-html = "local/docs/rapidoc.html"
6 changes: 3 additions & 3 deletions examples/actix-app/config/openapi/auth.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Authentication"
[[endpoints]]
path = "/auth/login"
method = "POST"
summary = "Account login"
summary = "Logins the user account"
securities = []

[endpoints.body]
Expand All @@ -14,9 +14,9 @@ password = { type = "string", format = "password", description = "User password"
[[endpoints]]
path = "/auth/refresh"
method = "GET"
summary = "Refreshes access token"
summary = "Refreshes the access token"

[[endpoints]]
path = "/auth/logout"
method = "POST"
summary = "Account logout"
summary = "Logouts the user account"
File renamed without changes.
1 change: 0 additions & 1 deletion examples/actix-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(async_fn_in_trait)]
#![feature(lazy_cell)]
#![feature(let_chains)]

mod controller;
mod domain;
Expand Down
34 changes: 21 additions & 13 deletions examples/actix-app/src/middleware/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ where

fn call(&self, req: ServiceRequest) -> Self::Future {
let mut req = Request::from(req);
if let Ok(claims) = req.parse_jwt_claims(JwtClaims::shared_key()) &&
let Ok(mut user_session) = UserSession::<Uuid>::try_from_jwt_claims(claims)
{
if let Ok(session_id) = req.parse_session_id() {
user_session.set_session_id(session_id);
match req.parse_jwt_claims(JwtClaims::shared_key()) {
Ok(claims) => {
if let Ok(mut user_session) = UserSession::<Uuid>::try_from_jwt_claims(claims) {
if let Ok(session_id) = req.parse_session_id() {
user_session.set_session_id(session_id);
}
req.set_data(user_session);
} else {
return Box::pin(async move {
let message = "401 Unauthorized: invalid JWT claims";
let rejection = Rejection::with_message(message).context(&req).into();
let result: zino::Result<Self::Response> = Err(rejection);
result.map_err(|err| err.into())
});
}
}
Err(rejection) => {
return Box::pin(async move {
let result: zino::Result<Self::Response> = Err(rejection.into());
result.map_err(|err| err.into())
});
}
req.set_data(user_session);
} else {
return Box::pin(async move {
let message = "401 Unauthorized: login is required";
let rejection = Rejection::with_message(message).context(&req).into();
let result: zino::Result<Self::Response> = Err(rejection);
return result.map_err(|err| err.into());
});
}

let req = ServiceRequest::from(req);
Expand Down
8 changes: 4 additions & 4 deletions examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.11.3"
version = "0.11.4"
features = ["axum", "export-pdf"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.12.3"
version = "0.12.4"
features = [
"connector",
"connector-arrow",
Expand All @@ -33,8 +33,8 @@ features = [

[dependencies.zino-derive]
path = "../../zino-derive"
version = "0.9.3"
version = "0.9.4"

[dependencies.zino-model]
path = "../../zino-model"
version = "0.9.3"
version = "0.9.4"
2 changes: 1 addition & 1 deletion examples/axum-app/config/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ span = { "http.method" = "string", "http.target" = "string", "http.status_code"
app-name = "data-cube"

[openapi]
custom-html = "assets/docs/rapidoc.html"
custom-html = "local/docs/rapidoc.html"
6 changes: 3 additions & 3 deletions examples/axum-app/config/openapi/auth.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Authentication"
[[endpoints]]
path = "/auth/login"
method = "POST"
summary = "Account login"
summary = "Logins the user account"
securities = []

[endpoints.body]
Expand All @@ -14,9 +14,9 @@ password = { type = "string", format = "password", description = "User password"
[[endpoints]]
path = "/auth/refresh"
method = "GET"
summary = "Refreshes access token"
summary = "Refreshes the access token"

[[endpoints]]
path = "/auth/logout"
method = "POST"
summary = "Account logout"
summary = "Logouts the user account"
File renamed without changes.
1 change: 0 additions & 1 deletion examples/axum-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(async_fn_in_trait)]
#![feature(lazy_cell)]
#![feature(let_chains)]

mod controller;
mod domain;
Expand Down
29 changes: 14 additions & 15 deletions examples/axum-app/src/middleware/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ use zino::{prelude::*, Request, Result};
use zino_model::user::{JwtAuthService, User};

pub async fn init_user_session(mut req: Request, next: Next<Body>) -> Result<Response> {
if let Ok(claims) = req.parse_jwt_claims(JwtClaims::shared_key()) {
match User::verify_jwt_claims(&claims).await {
Ok(verified) => {
if verified &&
let Ok(mut user_session) = UserSession::<Uuid>::try_from_jwt_claims(claims)
{
if let Ok(session_id) = req.parse_session_id() {
user_session.set_session_id(session_id);
}
req.set_data(user_session);
} else {
reject!(req, unauthorized, "invalid JWT claims");
let claims = req
.parse_jwt_claims(JwtClaims::shared_key())
.map_err(|rejection| rejection.context(&req))?;
match User::verify_jwt_claims(&claims).await {
Ok(verified) => {
if verified {
let mut user_session = UserSession::<Uuid>::try_from_jwt_claims(claims)
.extract(&req)?;
if let Ok(session_id) = req.parse_session_id() {
user_session.set_session_id(session_id);
}
req.set_data(user_session);
} else {
reject!(req, unauthorized, "invalid JWT claims");
}
Err(err) => reject!(req, unauthorized, err),
}
} else {
reject!(req, unauthorized, "login is required");
Err(err) => reject!(req, unauthorized, err),
}
Ok(next.run(req.into()).await)
}
6 changes: 3 additions & 3 deletions examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ features = ["derive"]

[dependencies.zino]
path = "../../zino"
version = "0.11.3"
version = "0.11.4"
features = ["dioxus"]

[dependencies.zino-core]
path = "../../zino-core"
version = "0.12.3"
version = "0.12.4"
features = ["orm-sqlite"]

[dependencies.zino-model]
path = "../../zino-model"
version = "0.9.3"
version = "0.9.4"
6 changes: 3 additions & 3 deletions zino-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-core"
description = "Core types and traits for zino."
version = "0.12.3"
version = "0.12.4"
rust-version = "1.72"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -104,7 +104,7 @@ mime_guess = "2.0.4"
multer = "2.1.0"
parking_lot = "0.12.1"
rand = "0.8.5"
regex = "1.9.4"
regex = "1.9.5"
reqwest-middleware = "0.2.3"
reqwest-retry = "0.2.3"
reqwest-tracing = "0.4.6"
Expand Down Expand Up @@ -181,7 +181,7 @@ features = [
]

[dependencies.tera]
version = "1.19.0"
version = "1.19.1"
optional = true

[dependencies.tracing-subscriber]
Expand Down
12 changes: 8 additions & 4 deletions zino-core/src/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ pub trait RequestContext {
T: Default + Serialize + DeserializeOwned,
K: MACLike,
{
let mut validation = Validation::new();
let (param, mut token) = match self.get_query("access_token") {
Some(access_token) => ("access_token", access_token),
None => ("authorization", ""),
Expand All @@ -545,6 +544,11 @@ pub trait RequestContext {
.strip_prefix("Bearer ")
.unwrap_or(authorization);
}
if token.is_empty() {
let mut validation = Validation::new();
validation.record(param, "the JWT token is absent");
return Err(Rejection::bad_request(validation).context(self));
}

let mut options = auth::default_verification_options();
options.reject_before = self
Expand All @@ -554,12 +558,12 @@ pub trait RequestContext {
options.required_nonce = self.get_query("nonce").map(|s| s.to_owned());

match key.verify_token(token, Some(options)) {
Ok(claims) => return Ok(JwtClaims(claims)),
Ok(claims) => Ok(JwtClaims(claims)),
Err(err) => {
validation.record(param, err.to_string());
let message = format!("401 Unauthorized: {err}");
Err(Rejection::with_message(message).context(self))
}
}
Err(Rejection::bad_request(validation).context(self))
}

/// Returns a `Response` or `Rejection` from an SQL query validation.
Expand Down
6 changes: 3 additions & 3 deletions zino-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-derive"
description = "Derived traits for zino."
version = "0.9.3"
version = "0.9.4"
rust-version = "1.72"
edition = "2021"
license = "MIT"
Expand All @@ -17,9 +17,9 @@ proc-macro = true
convert_case = "0.6.0"
proc-macro2 = "1.0.66"
quote = "1.0.33"
syn = "2.0.29"
syn = "2.0.31"

[dependencies.zino-core]
path = "../zino-core"
version = "0.12.3"
version = "0.12.4"
features = ["orm"]
8 changes: 4 additions & 4 deletions zino-model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zino-model"
description = "Domain models for zino."
version = "0.9.3"
version = "0.9.4"
rust-version = "1.72"
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -29,7 +29,7 @@ maintainer-id = []
edition = []

[dependencies]
regex = "1.9.4"
regex = "1.9.5"
strum_macros = "0.25.2"

[dependencies.serde]
Expand All @@ -38,9 +38,9 @@ features = ["derive"]

[dependencies.zino-core]
path = "../zino-core"
version = "0.12.3"
version = "0.12.4"
features = ["orm"]

[dependencies.zino-derive]
path = "../zino-derive"
version = "0.9.3"
version = "0.9.4"
Loading

0 comments on commit d5e81b9

Please sign in to comment.