From c03321bc059ed733970d8a696acb461428b1d284 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sat, 10 Apr 2021 14:44:40 +0300 Subject: dunno --- src/auth.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index e22262c..95f2378 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,12 +1,14 @@ use crate::error::Error; use crate::schema::{Db, Transaction}; +use anyhow::{anyhow, Context, Result}; use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation}; use serde::{Deserialize, Serialize}; +use thiserror::Error; use warp::header::headers_cloned; use warp::http::header::{HeaderMap, HeaderValue, AUTHORIZATION}; -use warp::{reject, Filter, Rejection}; -use thiserror::Error; -use anyhow::*; +use warp::reject; +use warp::reject::Reject; +use warp::{Filter, Rejection}; const BEARER: &str = "Bearer "; const PUBLIC_KEY_PEM: &str = "-----BEGIN PUBLIC KEY----- @@ -65,6 +67,18 @@ struct Claims { // found: String, // }, // } +// impl warp::reject::Reject for Nope {} + +#[derive(Debug)] +struct LessThanTenError {} + +impl Reject for LessThanTenError {} + +// impl From for Rejection { +// fn from(other: LessThanTenError) -> Self { +// warp::reject::custom(other) +// } +// } pub fn with_auth( db: Db, @@ -75,8 +89,6 @@ pub fn with_auth( .and_then(authorize) } -impl warp::reject::Reject for Nope {} - async fn authorize((db, headers): (Db, HeaderMap)) -> Result { match jwt_from_header(&headers) { Ok(jwt) => { @@ -92,7 +104,8 @@ async fn authorize((db, headers): (Db, HeaderMap)) -> Result return Err(anyhow!("missing!")); + Err(e) => return Err(anyhow!("missing!")), + // warp error } } -- cgit v1.2.3-70-g09d2