use std::fmt::Display;
use std::sync::Arc;
use self::adapter::GateAdapter;
use crate::authz::access_hierarchy::AccessHierarchy;
use crate::codecs::Codec;
pub mod adapter;
pub mod bearer;
#[cfg(feature = "cookies")]
pub mod cookie;
#[cfg(feature = "oauth2")]
pub mod oauth2;
#[derive(Clone, Debug, Default)]
pub struct Gate;
impl Gate {
#[cfg(feature = "cookies")]
pub fn cookie<C, R, G>(issuer: &str, codec: Arc<C>) -> cookie::CookieGate<C, R, G>
where
C: Codec,
R: AccessHierarchy + Eq + Display + Default,
G: Eq,
{
cookie::CookieGate::new_with_codec(issuer, codec)
}
pub fn bearer<C, R, G>(
issuer: &str,
codec: Arc<C>,
) -> bearer::BearerGate<C, R, G, bearer::JwtConfig<R, G>>
where
C: Codec,
R: AccessHierarchy + Eq + Display + Default,
G: Eq + Clone,
{
bearer::BearerGate::new_with_codec(issuer, codec)
}
#[cfg(feature = "oauth2")]
pub fn oauth2<R, G>() -> oauth2::OAuth2Gate<R, G>
where
R: AccessHierarchy + Eq + Display + Default + Send + Sync + 'static,
G: Eq + Clone + Send + Sync + 'static,
{
oauth2::OAuth2Gate::new()
}
}
pub trait GateExt: Sized {
fn adapt_with<A>(self, adapter: A) -> A::Output
where
A: GateAdapter<Self>,
{
adapter.adapt(self)
}
}