use std::fmt::Debug;
use dyn_problem::Problem;
use either::Either;
use futures::future::BoxFuture;
use http::{HeaderMap, Method};
use http_uri::invariant::AbsoluteHttpUri;
use manas_http::header::www_authenticate::WWWAuthenticate;
use crate::common::credentials::RequestCredentials;
pub mod impl_;
pub trait CRAuthenticationScheme: Debug + Send + Sync + 'static {
type Credentials: RequestCredentials;
fn resolve_or_challenge(
&self,
uri: &AbsoluteHttpUri,
method: &Method,
headers: &HeaderMap,
) -> BoxFuture<'static, CRResolutionResult<Self::Credentials>>;
}
#[derive(Debug, Clone)]
pub struct CRAuthenticationChallenge {
pub www_authenticate: WWWAuthenticate,
pub ext_headers: HeaderMap,
}
pub type DynCRAuthenticationScheme<C> = dyn CRAuthenticationScheme<Credentials = C>;
pub type CRResolutionResult<Creds> = Result<Creds, Either<CRAuthenticationChallenge, Problem>>;