pub struct BearerAuthLayer<Sess, P>{ /* private fields */ }Expand description
Tower Layer mounting the perimeter authentication boundary.
Wrap an axum router with .layer(BearerAuthLayer::new(provider, config)).
Mount at HTTP-edge granularity, not per-route — every authenticated
transport should sit behind this layer. Routes that need anonymous
access (health endpoints, the OIDC RP sub-router itself, public
landing pages) stay outside.
Two generic parameters:
Sess— the consumer’s perimeter session type. WhateverAuthProvider::verify_tokenreturns lands inreq.extensions()for handlers to read viareq.extensions().get::<Sess>().P: ?Sized— theAuthProviderimpl. Both concrete types (Arc<MyProvider>) and trait objects (Arc<dyn AuthProvider<Sess>>) are supported.
Implementations§
Source§impl<Sess, P> BearerAuthLayer<Sess, P>
impl<Sess, P> BearerAuthLayer<Sess, P>
Sourcepub fn new(
provider: Arc<P>,
config: BearerAuthConfig,
) -> BearerAuthLayer<Sess, P>
pub fn new( provider: Arc<P>, config: BearerAuthConfig, ) -> BearerAuthLayer<Sess, P>
Build the Layer from an AuthProvider handle and a
BearerAuthConfig. Production wiring at app boot looks like:
ⓘ
let provider: Arc<dyn AuthProvider<MySession>> =
Arc::new(MyConcreteProvider::new(verifier, db_pool));
let layer = BearerAuthLayer::new(
provider,
BearerAuthConfig::new(
my_cookies::ACCESS_COOKIE,
Arc::new(|jar| my_cookies::clear_session_cookies(jar)),
[].into(), // path_exempt — exempt nothing (fail-closed default)
),
);
app.layer(layer)Trait Implementations§
Source§impl<Sess, P> Clone for BearerAuthLayer<Sess, P>
impl<Sess, P> Clone for BearerAuthLayer<Sess, P>
Source§fn clone(&self) -> BearerAuthLayer<Sess, P>
fn clone(&self) -> BearerAuthLayer<Sess, P>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Inner, Sess, P> Layer<Inner> for BearerAuthLayer<Sess, P>
impl<Inner, Sess, P> Layer<Inner> for BearerAuthLayer<Sess, P>
Source§type Service = BearerAuthService<Inner, Sess, P>
type Service = BearerAuthService<Inner, Sess, P>
The wrapped service
Auto Trait Implementations§
impl<Sess, P> !RefUnwindSafe for BearerAuthLayer<Sess, P>
impl<Sess, P> !UnwindSafe for BearerAuthLayer<Sess, P>
impl<Sess, P> Freeze for BearerAuthLayer<Sess, P>where
P: ?Sized,
impl<Sess, P> Send for BearerAuthLayer<Sess, P>where
P: ?Sized,
impl<Sess, P> Sync for BearerAuthLayer<Sess, P>where
P: ?Sized,
impl<Sess, P> Unpin for BearerAuthLayer<Sess, P>where
P: ?Sized,
impl<Sess, P> UnsafeUnpin for BearerAuthLayer<Sess, P>where
P: ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more