1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

update jsonwebtoken, futures, and hyper and co

This commit is contained in:
Dominic 2020-04-14 17:44:07 +02:00
parent fbcc626478
commit f425f21ff3
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
11 changed files with 83 additions and 71 deletions

View file

@ -1,17 +1,21 @@
use crate::HeaderName;
use cookie::CookieJar;
use futures::{future, future::Future};
use futures_util::{future, future::{FutureExt, TryFutureExt}};
use gotham::{
handler::HandlerFuture,
middleware::{Middleware, NewMiddleware},
state::{FromState, State}
};
use hyper::header::{AUTHORIZATION, HeaderMap};
use jsonwebtoken::errors::ErrorKind;
use jsonwebtoken::{
errors::ErrorKind,
DecodingKey
};
use serde::de::DeserializeOwned;
use std::{
marker::PhantomData,
panic::RefUnwindSafe
panic::RefUnwindSafe,
pin::Pin
};
pub use jsonwebtoken::Validation as AuthValidation;
@ -248,7 +252,7 @@ where
};
// validate the token
let data : Data = match jsonwebtoken::decode(&token, &secret, &self.validation) {
let data : Data = match jsonwebtoken::decode(&token, &DecodingKey::from_secret(&secret), &self.validation) {
Ok(data) => data.claims,
Err(e) => match dbg!(e.into_kind()) {
ErrorKind::ExpiredSignature => return AuthStatus::Expired,
@ -266,9 +270,9 @@ where
Data : DeserializeOwned + Send + 'static,
Handler : AuthHandler<Data>
{
fn call<Chain>(self, mut state : State, chain : Chain) -> Box<HandlerFuture>
fn call<Chain>(self, mut state : State, chain : Chain) -> Pin<Box<HandlerFuture>>
where
Chain : FnOnce(State) -> Box<HandlerFuture>
Chain : FnOnce(State) -> Pin<Box<HandlerFuture>>
{
// put the source in our state, required for e.g. openapi
state.put(self.source.clone());
@ -278,7 +282,7 @@ where
state.put(status);
// call the rest of the chain
Box::new(chain(state).and_then(|(state, res)| future::ok((state, res))))
chain(state).and_then(|(state, res)| future::ok((state, res))).boxed()
}
}