mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
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<A: CheckAuthentication> {
|
|
pub inner: AuthInfo,
|
|
pub _provider_type: PhantomData<A>,
|
|
}
|
|
|
|
impl<T: CheckAuthentication> From<AuthInfo> for AuthInfoExtractor<T> {
|
|
fn from(value: AuthInfo) -> Self {
|
|
AuthInfoExtractor {
|
|
inner: value,
|
|
_provider_type: PhantomData::<T>,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<A> FromRequest for AuthInfoExtractor<A>
|
|
where
|
|
A: CheckAuthentication,
|
|
{
|
|
type Error = Error;
|
|
type Future = Ready<Result<Self, Self::Error>>;
|
|
|
|
fn extract(req: &HttpRequest) -> Self::Future {
|
|
let result = req.app_data::<Data<A>>().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)
|
|
}
|
|
}
|