pub struct BearerToken(pub String);Expand description
Extracts the token from an Authorization: Bearer <token> header.
The Bearer scheme prefix is matched case-insensitively and stripped; the
remaining token is trimmed. Extraction fails with 401 Unauthorized if the
Authorization header is missing or does not use the Bearer scheme.
use churust_core::{Churust, BearerToken, TestClient};
let app = Churust::server()
.routing(|r| {
r.get("/me", |BearerToken(t): BearerToken| async move {
format!("token={t}")
});
})
.build();
let res = TestClient::new(app)
.get("/me")
.header("authorization", "Bearer abc123")
.send()
.await;
assert_eq!(res.text(), "token=abc123");Tuple Fields§
§0: StringThe extracted bearer token (without the Bearer prefix).
Trait Implementations§
Source§impl Clone for BearerToken
impl Clone for BearerToken
Source§fn clone(&self) -> BearerToken
fn clone(&self) -> BearerToken
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 Debug for BearerToken
impl Debug for BearerToken
Source§impl FromCallParts for BearerToken
impl FromCallParts for BearerToken
Source§impl OptionalFromCallParts for BearerToken
Absent means no Authorization header. A header that is present but is not
a Bearer credential stays a 401: the client did attempt to authenticate,
and treating a malformed scheme as “anonymous” is how an auth check gets
skipped by accident.
impl OptionalFromCallParts for BearerToken
Absent means no Authorization header. A header that is present but is not
a Bearer credential stays a 401: the client did attempt to authenticate,
and treating a malformed scheme as “anonymous” is how an auth check gets
skipped by accident.
Source§fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Build
Self, or Ok(None) when the input is absent. Reserve Err for
input that was supplied and is wrong.Auto Trait Implementations§
impl Freeze for BearerToken
impl RefUnwindSafe for BearerToken
impl Send for BearerToken
impl Sync for BearerToken
impl Unpin for BearerToken
impl UnsafeUnpin for BearerToken
impl UnwindSafe for BearerToken
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