use actix_web::{dev::Payload, web::Data, FromRequest, HttpRequest}; use std::{ future::{ready, Ready}, marker::PhantomData, }; use crate::error::Error; use super::{AuthInfo, CheckAuthentication}; pub struct AuthInfoExtractor { pub inner: AuthInfo, pub _provider_type: PhantomData, } impl From for AuthInfoExtractor { fn from(value: AuthInfo) -> Self { AuthInfoExtractor { inner: value, _provider_type: PhantomData::, } } } impl FromRequest for AuthInfoExtractor where A: CheckAuthentication, { type Error = Error; type Future = Ready>; fn extract(req: &HttpRequest) -> Self::Future { let result = req.app_data::>().unwrap().validate(req); ready(result.map(|auth_info| Self { inner: auth_info, _provider_type: PhantomData, })) } fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future { Self::extract(req) } }