AuthContextBuilder

Struct AuthContextBuilder 

Source
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

Source

pub fn subject(self, sub: impl Into<String>) -> Self

Set subject (user ID)

Source

pub fn sub(self, sub: impl Into<String>) -> Self

👎Deprecated since 2.0.5: Use .subject() instead to avoid confusion with std::ops::Sub trait

Set subject (user ID) - deprecated alias

Source

pub fn iss(self, iss: impl Into<String>) -> Self

Set issuer

Source

pub fn aud(self, aud: impl Into<String>) -> Self

Set audience

Source

pub fn exp(self, exp: u64) -> Self

Set expiration (Unix timestamp)

Source

pub fn iat(self, iat: u64) -> Self

Set issued at (Unix timestamp)

Source

pub fn nbf(self, nbf: u64) -> Self

Set not before (Unix timestamp)

Source

pub fn jti(self, jti: impl Into<String>) -> Self

Set JWT ID

Source

pub fn user(self, user: UserInfo) -> Self

Set user information

Source

pub fn roles(self, roles: Vec<String>) -> Self

Set roles

Source

pub fn role(self, role: impl Into<String>) -> Self

Add a single role

Source

pub fn permissions(self, permissions: Vec<String>) -> Self

Set permissions

Source

pub fn permission(self, permission: impl Into<String>) -> Self

Add a single permission

Source

pub fn scopes(self, scopes: Vec<String>) -> Self

Set scopes

Source

pub fn scope(self, scope: impl Into<String>) -> Self

Add a single scope

Source

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.

Source

pub fn authenticated_at(self, authenticated_at: SystemTime) -> Self

Set authenticated at timestamp

Source

pub fn expires_at(self, expires_at: SystemTime) -> Self

Set expires at timestamp

Source

pub fn token(self, token: TokenInfo) -> Self

Set token information

Source

pub fn provider(self, provider: impl Into<String>) -> Self

Set auth provider

Source

pub fn dpop_jkt(self, jkt: impl Into<String>) -> Self

Set DPoP JWK thumbprint (requires dpop feature)

Source

pub fn metadata(self, key: impl Into<String>, value: Value) -> Self

Add custom metadata

Source

pub fn build(self) -> Result<AuthContext, AuthError>

Build the AuthContext

§Errors

Returns error if required fields are missing:

  • sub (subject)
  • user (user information)
  • provider (auth provider)

Trait Implementations§

Source§

impl Default for AuthContextBuilder

Source§

fn default() -> AuthContextBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more