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: StringJWT 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: u64JWT 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: StringAuthentication Context Class Reference per OIDC Core §2.
Typical values: "aal1" / "aal2" / "aal3". Handlers gating
step-up read this directly.
Implementations§
Source§impl AuthClaims
impl AuthClaims
Sourcepub fn is_super_admin(&self) -> bool
pub fn is_super_admin(&self) -> bool
Returns true if the caller is an admin with unrestricted access
(empty allowed_contexts).
Sourcepub fn has_context_access(&self, context_id: &str) -> bool
pub fn has_context_access(&self, context_id: &str) -> bool
Returns true if the caller has access to the given context — as a super
admin, or because one of their allowed_contexts is 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.
Sourcepub fn with_delegated_contexts(&self, extra: &[String]) -> Self
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.
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).
Sourcepub fn require_context(&self, context_id: &str) -> Result<(), AppError>
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.
Sourcepub fn default_context(&self) -> Option<&str>
pub fn default_context(&self) -> Option<&str>
If the caller has exactly one allowed context, return it.
Sourcepub fn require_read(&self) -> Result<(), AppError>
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.
Sourcepub fn require_write(&self) -> Result<(), AppError>
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.
Sourcepub fn require_admin(&self) -> Result<(), AppError>
pub fn require_admin(&self) -> Result<(), AppError>
Require the caller to have Admin role.
Sourcepub fn require_manage(&self) -> Result<(), AppError>
pub fn require_manage(&self) -> Result<(), AppError>
Require the caller to have Admin or Initiator role.
Sourcepub fn require_super_admin(&self) -> Result<(), AppError>
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
impl Clone for AuthClaims
Source§fn clone(&self) -> AuthClaims
fn clone(&self) -> AuthClaims
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthClaims
impl Debug for AuthClaims
Source§impl Default for AuthClaims
impl Default for AuthClaims
Source§fn default() -> AuthClaims
fn default() -> AuthClaims
Source§impl<S: AuthState> FromRequestParts<S> for AuthClaims
impl<S: AuthState> FromRequestParts<S> for AuthClaims
Auto Trait Implementations§
impl Freeze for AuthClaims
impl RefUnwindSafe for AuthClaims
impl Send for AuthClaims
impl Sync for AuthClaims
impl Unpin for AuthClaims
impl UnsafeUnpin for AuthClaims
impl UnwindSafe for AuthClaims
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
Source§impl<T> BorrowUnordered for T
impl<T> BorrowUnordered for T
fn as_unordered(&self) -> &Unordered<T>
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Source§impl<T> InitializableFromZeroed for Twhere
T: Default,
impl<T> InitializableFromZeroed for Twhere
T: Default,
Source§unsafe fn initialize(place: *mut T)
unsafe fn initialize(place: *mut T)
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, U, C> IntoWithContext<U, C> for Twhere
U: FromWithContext<T, C>,
impl<T, U, C> IntoWithContext<U, C> for Twhere
U: FromWithContext<T, C>,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ResourceProvider<()> for T
impl<T> ResourceProvider<()> for T
Source§fn get_resource(&self) -> &()
fn get_resource(&self) -> &()
T.