Expand description
Authentication support for WebSocket connections WebSocket authentication support
This module provides authentication infrastructure for WebSocket connections, allowing token validation before the WebSocket upgrade completes.
§Example
ⓘ
use rustapi_ws::auth::{WsAuthConfig, TokenExtractor, TokenValidator, Claims};
use async_trait::async_trait;
struct MyTokenValidator;
#[async_trait]
impl TokenValidator for MyTokenValidator {
async fn validate(&self, token: &str) -> Result<Claims, AuthError> {
// Validate JWT or other token format
Ok(Claims::new("user_123"))
}
}
let config = WsAuthConfig::new(Box::new(MyTokenValidator))
.extractor(TokenExtractor::Header("Authorization".to_string()));Structs§
- Accept
AllValidator - A simple token validator that accepts any non-empty token
- Claims
- Claims extracted from a validated token
- Reject
AllValidator - A token validator that rejects all tokens
- Static
Token Validator - A token validator that validates against a static list of valid tokens
- WsAuth
Config - Configuration for WebSocket authentication
Enums§
- Auth
Error - Error type for WebSocket authentication
- Token
Extractor - Specifies where to extract the authentication token from
Traits§
- Token
Validator - Trait for validating authentication tokens