pub struct TokenExtractor { /* private fields */ }Expand description
Extracts tokens from HTTP request parts according to configured sources.
Implementations§
Source§impl TokenExtractor
impl TokenExtractor
Sourcepub fn new(sources: Vec<TokenSourceKind>) -> Self
pub fn new(sources: Vec<TokenSourceKind>) -> Self
Create a new extractor with the given ordered sources.
Sourcepub fn bearer_only() -> Self
pub fn bearer_only() -> Self
Bearer-only extractor.
Sourcepub fn with_source(self, src: TokenSourceKind) -> Self
pub fn with_source(self, src: TokenSourceKind) -> Self
Add a source.
Sourcepub fn sources(&self) -> &[TokenSourceKind]
pub fn sources(&self) -> &[TokenSourceKind]
Ordered sources.
Sourcepub fn extract_token(&self, parts: &Parts, query: &str) -> Option<String>
Available on crate feature axum only.
pub fn extract_token(&self, parts: &Parts, query: &str) -> Option<String>
axum only.Extract the first token found according to source order.
When the axum feature is enabled the first argument is &http::request::Parts
(from axum’s request). The second argument is the raw query string
(e.g. "token=abc&foo=bar" without leading ?).
Returns None if no token was found in any source.
Sourcepub fn extract_from_parts(
&self,
auth_header: Option<&str>,
cookie_header: Option<&str>,
query: &str,
) -> Option<String>
pub fn extract_from_parts( &self, auth_header: Option<&str>, cookie_header: Option<&str>, query: &str, ) -> Option<String>
Extract token without Parts (query and cookie header strings only).
Useful when axum is not enabled or for tests.
Sourcepub fn require_token(
&self,
parts: &Parts,
query: &str,
) -> Result<String, WsAuthError>
Available on crate feature axum only.
pub fn require_token( &self, parts: &Parts, query: &str, ) -> Result<String, WsAuthError>
axum only.Validate presence of token, returning a typed error.
Trait Implementations§
Source§impl Clone for TokenExtractor
impl Clone for TokenExtractor
Source§fn clone(&self) -> TokenExtractor
fn clone(&self) -> TokenExtractor
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 TokenExtractor
impl Debug for TokenExtractor
Auto Trait Implementations§
impl Freeze for TokenExtractor
impl RefUnwindSafe for TokenExtractor
impl Send for TokenExtractor
impl Sync for TokenExtractor
impl Unpin for TokenExtractor
impl UnsafeUnpin for TokenExtractor
impl UnwindSafe for TokenExtractor
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