Skip to content

Commit

Permalink
use published version of mews & fix to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanarus committed Oct 29, 2024
1 parent a25781e commit b3cc337
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ohkami/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sha2 = { version = "0.10", default-features = false }

num_cpus = { version = "1.16", optional = true }
futures-util = { version = "0.3", optional = true, default-features = false, features = ["io", "async-await-macro"] }
mews = { git = "https://github.com/ohkami-rs/mews", optional = true }
mews = { version = "0.1", optional = true }


[features]
Expand Down
12 changes: 6 additions & 6 deletions ohkami/src/fang/builtin/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{Fang, FangProc, IntoResponse, Request, Response};
use std::{borrow::Cow, marker::PhantomData};
use serde::{Serialize, Deserialize};
use base64::engine::{Engine as _, general_purpose::URL_SAFE as BASE64URL};
use base64::engine::{Engine as _, general_purpose::URL_SAFE_NO_PAD as BASE64URL};


/// # Builtin fang and helper for JWT config
Expand Down Expand Up @@ -303,20 +303,20 @@ impl<Payload: for<'de> Deserialize<'de>> JWT<Payload> {
}

let header_part = parts.next()
.ok_or_else(|| Response::BadRequest())?;
.ok_or_else(Response::Unauthorized)?;
let header: Header = part_value(header_part)?;
if header.get("typ").is_some_and(|typ| !typ.as_str().unwrap_or_default().eq_ignore_ascii_case("JWT")) {
return Err(Response::BadRequest())
}
if header.get("cty").is_some_and(|cty| !cty.as_str().unwrap_or_default().eq_ignore_ascii_case("JWT")) {
return Err(Response::BadRequest())
}
if header.get("alg").ok_or_else(|| Response::BadRequest())? != self.alg_str() {
if header.get("alg").ok_or_else(Response::Unauthorized)? != self.alg_str() {
return Err(Response::BadRequest())
}

let payload_part = parts.next()
.ok_or_else(|| Response::BadRequest())?;
.ok_or_else(Response::Unauthorized)?;
let payload: Payload = part_value(payload_part)?;
let now = crate::util::unix_timestamp();
if payload.get("nbf").is_some_and(|nbf| nbf.as_u64().unwrap_or(0) > now) {
Expand All @@ -330,9 +330,9 @@ impl<Payload: for<'de> Deserialize<'de>> JWT<Payload> {
}

let signature_part = parts.next()
.ok_or_else(|| Response::BadRequest())?;
.ok_or_else(Response::Unauthorized)?;
let requested_signature = BASE64URL.decode(signature_part)
.map_err(|_| Response::BadRequest().with_text("invalid base64"))?;
.map_err(|_| Response::Unauthorized())?;

let is_correct_signature = {
use ::sha2::{Sha256, Sha384, Sha512};
Expand Down
4 changes: 2 additions & 2 deletions ohkami/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const _: () = {
///
/// ## handler
///
/// any `FnOnce(Connection) -> {impl Future<Output = ()> + Send} + Send + Sync`
/// any 'static `FnOnce(Connection) -> {impl Future<Output = ()> + Send} + Send + Sync`
pub fn upgrade<H, F, C: mews::connection::UnderlyingConnection>(
self,
handler: H
Expand All @@ -77,7 +77,7 @@ const _: () = {
///
/// ## handler
///
/// any `FnOnce(Connection) -> {impl Future<Output = ()> + Send} + Send + Sync`
/// any 'static `FnOnce(Connection) -> {impl Future<Output = ()> + Send} + Send + Sync`
pub fn upgrade_with<H, F, C: mews::connection::UnderlyingConnection>(self,
config: Config,
handler: H
Expand Down

0 comments on commit b3cc337

Please sign in to comment.