pub struct StaticAuthProvider { /* private fields */ }Expand description
Static bearer-token auth provider, suitable for dev and tests.
Validates that incoming Authorization headers match exactly one configured
bearer token. Returns Some(AuthContext) with subject = "static-bearer"
on match, an Err(ErrorCode::INVALID_REQUEST) on token mismatch, and an
Err(ErrorCode::INVALID_REQUEST) on missing header (because
AuthProvider::is_required defaults to true).
§Example
use pmcp_server_toolkit::auth::StaticAuthProvider;
let provider = StaticAuthProvider::new("dev-token-do-not-use-in-prod");§Security note
Token comparison uses [constant_time_eq] semantics via byte-wise XOR
accumulation to avoid timing-side-channel leaks during dev/test use.
Production callers should use pmcp’s OAuth2 + JWT validator pipeline
instead.
Implementations§
Trait Implementations§
Source§impl AuthProvider for StaticAuthProvider
impl AuthProvider for StaticAuthProvider
Source§fn validate_request<'life0, 'life1, 'async_trait>(
&'life0 self,
authorization_header: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<AuthContext>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn validate_request<'life0, 'life1, 'async_trait>(
&'life0 self,
authorization_header: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<AuthContext>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Validate an incoming request and extract authentication context. Read more
Source§fn auth_scheme(&self) -> &'static str
fn auth_scheme(&self) -> &'static str
Get the authentication scheme this provider uses (e.g., “Bearer”, “Basic”).
Source§fn is_required(&self) -> bool
fn is_required(&self) -> bool
Check if this provider requires authentication for all requests.
Auto Trait Implementations§
impl Freeze for StaticAuthProvider
impl RefUnwindSafe for StaticAuthProvider
impl Send for StaticAuthProvider
impl Sync for StaticAuthProvider
impl Unpin for StaticAuthProvider
impl UnsafeUnpin for StaticAuthProvider
impl UnwindSafe for StaticAuthProvider
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.