Skip to main content

AuthClaims

Struct AuthClaims 

Source
pub struct AuthClaims {
    pub did: String,
    pub role: Role,
    pub allowed_contexts: Vec<String>,
    pub session_id: String,
    pub access_expires_at: u64,
    pub amr: Vec<String>,
    pub acr: String,
}
Expand description

Extracted from a valid JWT Bearer token on protected routes.

Add this as a handler parameter to require authentication:

async fn handler(_auth: AuthClaims, ...) { }

Fields§

§did: String§role: Role§allowed_contexts: Vec<String>§session_id: String

JWT session_id claim. Carried through so handlers can do session-targeted operations (sign-out, refresh-token rotation) without re-decoding the JWT.

§access_expires_at: u64

JWT exp claim — Unix-second expiry. Surfaced so whoami-style endpoints can return the access-token lifetime without re-decoding.

§amr: Vec<String>

Authentication Methods References per [RFC 8176]. Mirrors Claims.amr from the bearer JWT. Handlers gating sensitive operations check this to decide whether a step-up is needed.

§acr: String

Authentication Context Class Reference per OIDC Core §2. Typical values: "aal1" / "aal2" / "aal3". Handlers gating step-up read this directly.

Implementations§

Source§

impl AuthClaims

Source

pub fn act_scope(&self) -> ActScope

This caller’s authority to act, decoded from (role, allowed_contexts).

Use this — or has_context_access, which is built on it — rather than inspecting allowed_contexts directly. An empty list means unrestricted for Role::Admin and nothing at all for every other role; a call site that tests is_empty() without the role gets one of those two cases backwards. See ActScope.

Source

pub fn is_super_admin(&self) -> bool

Returns true if the caller is an admin whose ActScope is unrestricted.

Source

pub fn has_context_access(&self, context_id: &str) -> bool

Returns true if the caller may act in the given context — because their ActScope is unrestricted, or because it names context_id itself or an ancestor of it (folder-level authority: admin of a parent context covers the whole subtree).

Ancestry is the segment-aware is_ancestor_or_self — a pure, store-free check over the verified JWT’s contexts. For today’s flat (single-segment, childless) contexts this is identical to the previous exact match.

Source

pub fn with_delegated_contexts(&self, extra: &[String]) -> Self

Clone these claims with extra contexts merged into allowed_contexts.

This is how a consented per-task delegation is realized: an approver who holds admin in a context authorizes one specific task, and the executor runs that one dispatch under the requester’s identity widened to include the delegated context. The widening lives only for the single consented, payload-bound, single-use execution — it is never persisted onto the session or the JWT, so the agent accrues no standing authority.

Never widens a super-admin (empty allowed_contexts already means “all contexts”, so there is nothing to add and replacing the empty list would wrongly narrow it) and is a no-op when extra is empty. Duplicates are dropped so repeated delegation can’t bloat the list.

Source

pub fn with_delegated_authority(&self, extra: &[String]) -> Self

Realize a consented grant for a single dispatch: the approval conferred full authority over extra, so the requester need hold no standing admin at all.

Unlike [with_delegated_contexts] — which widens context but keeps the requester’s role — this also lifts the role to Role::Admin, because the grant authorizes the exact bound task in full. That is what lets a purely unprivileged agent (a Reader that can act nowhere) execute a task an approver blessed: the approval is the authority. Ephemeral in exactly the same way as the context widening — built for one dispatch, never persisted to the session, JWT, or ACL — so the agent accrues no standing power.

A no-op when extra is empty (nothing was delegated — an ordinary same-context, already-authorized execution) and for a super-admin (already unrestricted; adding to the empty list would wrongly narrow it).

Source

pub fn require_context(&self, context_id: &str) -> Result<(), AppError>

Check that the caller has access to the given context.

Admins with an empty allowed_contexts list have unrestricted access.

Source

pub fn default_context(&self) -> Option<&str>

If the caller has exactly one allowed context, return it.

Source

pub fn require_read(&self) -> Result<(), AppError>

Require at least Reader role (all roles except Monitor).

Use for read-only endpoints that access business data (keys, contexts, DIDs). Monitor can only see metrics and health.

Source

pub fn require_write(&self) -> Result<(), AppError>

Require at least Application role (Admin, Initiator, or Application).

Use for write operations: signing, cache writes, and other actions that produce artifacts or modify state.

Source

pub fn require_admin(&self) -> Result<(), AppError>

Require the caller to have Admin role.

Source

pub fn require_manage(&self) -> Result<(), AppError>

Require the caller to have Admin or Initiator role.

Source

pub fn require_super_admin(&self) -> Result<(), AppError>

Require the caller to be a super admin (Admin + unrestricted).

Trait Implementations§

Source§

impl Clone for AuthClaims

Source§

fn clone(&self) -> AuthClaims

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuthClaims

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AuthClaims

Source§

fn default() -> AuthClaims

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

impl<S: AuthState> FromRequestParts<S> for AuthClaims

Source§

type Rejection = AppError

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request_parts( parts: &mut Parts, state: &S, ) -> Result<Self, Self::Rejection>

Perform the extraction.

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> At for T

Source§

fn at<M>(self, metadata: M) -> Meta<T, M>

Wraps self inside a Meta<Self, M> using the given metadata. 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> BorrowStripped for T

Source§

fn stripped(&self) -> &Stripped<T>

Source§

impl<T> BorrowUnordered for T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Clear for T

Source§

fn clear(&mut self)

Completely overwrites this value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<S, T> FromRequest<S, ViaParts> for T
where S: Send + Sync, T: FromRequestParts<S>,

Source§

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>

Perform the extraction.
Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

Source§

impl<T> InitializableFromZeroed for T
where T: Default,

Source§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
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, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ResourceProvider<()> for T

Source§

fn get_resource(&self) -> &()

Returns a reference to the resource of type T.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToOwned for T

Source§

type Owned = T

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, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = Infallible

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

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<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

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

Source§

fn vzip(self) -> V

Source§

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

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,

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