pub struct AuthCtx {
pub subject: String,
pub issuer: String,
pub audience: String,
pub scopes: Vec<String>,
pub kind: PrincipalKind,
pub raw_token: String,
pub expires_at: f64,
pub extra: HashMap<String, Value>,
}Expand description
Identity + claims for the current request. The single concrete type
that flows through the framework — outbound clients accept this, the
server-side auth layer produces it. Custom claims live in
Self::extra.
Fields§
§subject: Stringsub claim. User ID for users, service ID for services.
issuer: String§audience: String§scopes: Vec<String>§kind: PrincipalKind§raw_token: StringThe verbatim token. Used by AuthCtx::propagate for outbound calls.
expires_at: f64Unix-seconds expiry. f64 to stay JSON-compatible with the
Python and TS sides (which use number). 0.0 means “no
expiry recorded” (e.g. an anonymous context). Use
AuthCtx::expires_at_systime / AuthCtx::set_expires_at_systime
when interop with std::time::SystemTime is convenient.
extra: HashMap<String, Value>Claims not mapped to typed fields. Verifiers populate this with anything custom (e.g. tenant_id, role, agent_on_behalf_of).
Implementations§
Source§impl AuthCtx
impl AuthCtx
Sourcepub fn from_bearer(token: impl Into<String>) -> AuthCtx
pub fn from_bearer(token: impl Into<String>) -> AuthCtx
Wrap a bearer token without verification. For client-side code that already has a token (e.g., from a login flow) and wants to hand it to the framework’s outbound propagation.
Sourcepub fn from<T>(req: &Request<T>) -> AuthCtx
pub fn from<T>(req: &Request<T>) -> AuthCtx
Pull AuthCtx from a tonic request’s extensions, populated by
the inbound auth layer. Returns Self::anonymous if no layer
ran.
Sourcepub fn propagate<T>(&self, req: &mut Request<T>)
pub fn propagate<T>(&self, req: &mut Request<T>)
Copy the bearer token onto an outbound request so the caller’s identity rides along to the next service.
Sourcepub fn require_scope(&self, scope: &str) -> Result<(), Status>
pub fn require_scope(&self, scope: &str) -> Result<(), Status>
Authorize a single scope. Returns PermissionDenied if missing.
Convenient for Status returns from handlers.
pub fn is_anonymous(&self) -> bool
Sourcepub fn expires_at_systime(&self) -> SystemTime
pub fn expires_at_systime(&self) -> SystemTime
Convert expires_at (unix seconds) into a SystemTime. Returns
UNIX_EPOCH for an anonymous / unset context (expires_at == 0.0).
Sourcepub fn set_expires_at_systime(&mut self, t: SystemTime)
pub fn set_expires_at_systime(&mut self, t: SystemTime)
Set expires_at from a SystemTime. Convenience for verifiers
that already hold a SystemTime (e.g. JWT iat + max_age).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AuthCtx
impl<'de> Deserialize<'de> for AuthCtx
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AuthCtx, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AuthCtx, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for AuthCtx
impl Serialize for AuthCtx
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for AuthCtx
impl RefUnwindSafe for AuthCtx
impl Send for AuthCtx
impl Sync for AuthCtx
impl Unpin for AuthCtx
impl UnsafeUnpin for AuthCtx
impl UnwindSafe for AuthCtx
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request