pub struct AuthContext {
subject: Option<String>,
scopes: HashSet<String>,
is_local: bool,
org_name: Option<String>,
org_role: Option<String>,
group_roles: HashMap<String, String>,
}Expand description
Authorization context for service operations.
Carries identity and permission information through the service layer. Can be created from JWT claims or constructed directly for testing.
Fields§
§subject: Option<String>Subject identifier (user ID, service account, etc.).
scopes: HashSet<String>Granted scopes/permissions.
is_local: boolWhether this is a local/CLI context (implicitly trusted).
org_name: Option<String>Organization name (for org-scoped operations).
org_role: Option<String>Role within the organization (admin, member, etc.).
group_roles: HashMap<String, String>Group roles (group_id → role string).
Implementations§
Source§impl AuthContext
impl AuthContext
Sourcepub fn local() -> Self
pub fn local() -> Self
Creates a local context with full permissions.
Used for CLI access where the user has local filesystem access.
Sourcepub fn from_scopes(scopes: Vec<String>) -> Self
pub fn from_scopes(scopes: Vec<String>) -> Self
Creates a context from a list of scope strings.
§Arguments
scopes- List of scope strings (e.g.,["read", "write"]).
Sourcepub fn builder() -> AuthContextBuilder
pub fn builder() -> AuthContextBuilder
Creates a builder for constructing an auth context.
Sourcepub fn with_subject(self, subject: impl Into<String>) -> Self
pub fn with_subject(self, subject: impl Into<String>) -> Self
Sets the subject identifier.
Sourcepub fn has_org_access(&self) -> bool
pub fn has_org_access(&self) -> bool
Returns whether this context has org access.
Sourcepub fn has_permission(&self, permission: Permission) -> bool
pub fn has_permission(&self, permission: Permission) -> bool
Checks if the context has a specific permission.
Sourcepub fn has_any_permission(&self, permissions: &[Permission]) -> bool
pub fn has_any_permission(&self, permissions: &[Permission]) -> bool
Checks if the context has any of the specified permissions.
Sourcepub fn require(&self, permission: Permission) -> Result<()>
pub fn require(&self, permission: Permission) -> Result<()>
Requires a specific permission, returning an error if not granted.
§Errors
Returns Error::Unauthorized if the permission is not granted.
Sourcepub fn require_any(&self, permissions: &[Permission]) -> Result<()>
pub fn require_any(&self, permissions: &[Permission]) -> Result<()>
Requires any of the specified permissions.
§Errors
Returns Error::Unauthorized if none of the permissions are granted.
Sourcepub fn get_group_role(&self, group_id: &str) -> Option<GroupRole>
pub fn get_group_role(&self, group_id: &str) -> Option<GroupRole>
Sourcepub fn has_group_permission(&self, group_id: &str, min_role: GroupRole) -> bool
pub fn has_group_permission(&self, group_id: &str, min_role: GroupRole) -> bool
Trait Implementations§
Source§impl Clone for AuthContext
impl Clone for AuthContext
Source§fn clone(&self) -> AuthContext
fn clone(&self) -> AuthContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthContext
impl Debug for AuthContext
Auto Trait Implementations§
impl Freeze for AuthContext
impl RefUnwindSafe for AuthContext
impl Send for AuthContext
impl Sync for AuthContext
impl Unpin for AuthContext
impl UnwindSafe for AuthContext
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].