pub struct AuthMiddleware { /* private fields */ }
Expand description
Authentication middleware that adds auth headers.
§Examples
use pmcp::shared::{AuthMiddleware, Middleware};
use pmcp::types::{JSONRPCRequest, RequestId};
// Create auth middleware with API token
let auth_middleware = AuthMiddleware::new("Bearer api-token-12345".to_string());
let mut request = JSONRPCRequest {
jsonrpc: "2.0".to_string(),
method: "resources.read".to_string(),
params: Some(serde_json::json!({"uri": "file:///secure/data.txt"})),
id: RequestId::from(789i64),
};
// Process request and add authentication
auth_middleware.on_request(&mut request).await?;
// In a real implementation, the middleware would modify the request
// to include authentication information
Implementations§
Trait Implementations§
Source§impl Debug for AuthMiddleware
impl Debug for AuthMiddleware
Source§impl Middleware for AuthMiddleware
impl Middleware for AuthMiddleware
Source§fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 mut JSONRPCRequest,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 mut JSONRPCRequest,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called before a request is sent.
Source§fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
response: &'life1 mut JSONRPCResponse,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
response: &'life1 mut JSONRPCResponse,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called after a response is received.
Source§fn on_send<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_send<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a message is sent (any type).
Source§fn on_receive<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_receive<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a message is received (any type).
Source§fn on_notification<'life0, 'life1, 'async_trait>(
&'life0 self,
notification: &'life1 mut JSONRPCNotification,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_notification<'life0, 'life1, 'async_trait>(
&'life0 self,
notification: &'life1 mut JSONRPCNotification,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when an unsolicited notification is received. Read more
Auto Trait Implementations§
impl Freeze for AuthMiddleware
impl RefUnwindSafe for AuthMiddleware
impl Send for AuthMiddleware
impl Sync for AuthMiddleware
impl Unpin for AuthMiddleware
impl UnwindSafe for AuthMiddleware
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