use soaprs_core::{BoxFuture, SoapResult};
use crate::AuthorizationName;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Authentication<P> {
strategy: AuthorizationName,
principal: P,
}
impl<P> Authentication<P> {
pub fn new(strategy: impl Into<String>, principal: P) -> SoapResult<Self> {
Ok(Self {
strategy: AuthorizationName::new(strategy)?,
principal,
})
}
pub const fn strategy(&self) -> &AuthorizationName {
&self.strategy
}
pub const fn principal(&self) -> &P {
&self.principal
}
pub fn into_principal(self) -> P {
self.principal
}
}
pub trait Authenticator<C, P>: Send + Sync
where
C: Send,
P: Send,
{
fn authenticate(&self, credential: C) -> BoxFuture<'_, SoapResult<Authentication<P>>>;
}