pub struct AuthContextBuilder { /* private fields */ }Expand description
Builder for constructing AuthContext
Provides a fluent API for building auth contexts with validation.
§Example
ⓘ
use turbomcp_auth::context::AuthContext;
let ctx = AuthContext::builder()
.subject("user123")
.user(user_info)
.roles(vec!["admin".into()])
.permissions(vec!["read:posts".into()])
.provider("oauth2:google")
.build();Implementations§
Source§impl AuthContextBuilder
impl AuthContextBuilder
Sourcepub fn sub(self, sub: impl Into<String>) -> Self
👎Deprecated since 2.0.5: Use .subject() instead to avoid confusion with std::ops::Sub trait
pub fn sub(self, sub: impl Into<String>) -> Self
.subject() instead to avoid confusion with std::ops::Sub traitSet subject (user ID) - deprecated alias
Sourcepub fn permissions(self, permissions: Vec<String>) -> Self
pub fn permissions(self, permissions: Vec<String>) -> Self
Set permissions
Sourcepub fn permission(self, permission: impl Into<String>) -> Self
pub fn permission(self, permission: impl Into<String>) -> Self
Add a single permission
Sourcepub fn request_id(self, request_id: impl Into<String>) -> Self
pub fn request_id(self, request_id: impl Into<String>) -> Self
Set request ID for nonce/replay protection
This is used for request-level binding (DPoP nonces, one-time request tokens), NOT for session management. MCP requires stateless authentication where each request includes valid credentials.
Sourcepub fn authenticated_at(self, authenticated_at: SystemTime) -> Self
pub fn authenticated_at(self, authenticated_at: SystemTime) -> Self
Set authenticated at timestamp
Sourcepub fn expires_at(self, expires_at: SystemTime) -> Self
pub fn expires_at(self, expires_at: SystemTime) -> Self
Set expires at timestamp
Trait Implementations§
Source§impl Default for AuthContextBuilder
impl Default for AuthContextBuilder
Source§fn default() -> AuthContextBuilder
fn default() -> AuthContextBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for AuthContextBuilder
impl RefUnwindSafe for AuthContextBuilder
impl Send for AuthContextBuilder
impl Sync for AuthContextBuilder
impl Unpin for AuthContextBuilder
impl UnwindSafe for AuthContextBuilder
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