TokenExtractor

Trait TokenExtractor 

Source
pub trait TokenExtractor: Send + Sync {
    // Required methods
    fn extract_token(
        &self,
        headers: &dyn Headers,
    ) -> Result<Option<String>, JwtError>;
    fn description(&self) -> &str;
}
Expand description

Trait for extracting JWT tokens from HTTP headers

This trait defines the interface for extracting JWT tokens from HTTP headers. Implementations can extract tokens from different headers, with different prefixes, or using custom logic.

Required Methods§

Source

fn extract_token( &self, headers: &dyn Headers, ) -> Result<Option<String>, JwtError>

Extract a token from HTTP headers

§Parameters
  • headers - The HTTP headers to extract the token from
§Returns

Returns a Result containing an Option<String> with the token if found, or a JwtError if there was an error extracting the token. Returns Ok(None) if no token was found.

Source

fn description(&self) -> &str

Get a description of this extractor for debugging

Implementors§