pub struct AuthContext { /* private fields */ }Expand description
Authentication context available to all functions.
Implementations§
Source§impl AuthContext
impl AuthContext
Sourcepub fn unauthenticated() -> Self
pub fn unauthenticated() -> Self
Create an unauthenticated context.
Sourcepub fn authenticated(
user_id: Uuid,
roles: Vec<String>,
claims: HashMap<String, Value>,
) -> Self
pub fn authenticated( user_id: Uuid, roles: Vec<String>, claims: HashMap<String, Value>, ) -> Self
Create an authenticated context with a UUID user ID.
Sourcepub fn authenticated_without_uuid(
roles: Vec<String>,
claims: HashMap<String, Value>,
) -> Self
pub fn authenticated_without_uuid( roles: Vec<String>, claims: HashMap<String, Value>, ) -> Self
Create an authenticated context without requiring a UUID user ID.
Use this for auth providers that don’t use UUID subjects (e.g., Firebase,
Clerk). The raw subject string is available via subject() method
from the “sub” claim.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the user is authenticated.
Sourcepub fn require_user_id(&self) -> Result<Uuid>
pub fn require_user_id(&self) -> Result<Uuid>
Get the user ID, returning an error if not authenticated.
Sourcepub fn require_role(&self, role: &str) -> Result<()>
pub fn require_role(&self, role: &str) -> Result<()>
Require a specific role, returning an error if not present.
Sourcepub fn subject(&self) -> Option<&str>
pub fn subject(&self) -> Option<&str>
Get the raw subject claim.
This works with any provider’s subject format (UUID, email, custom ID).
For providers like Firebase or Clerk that don’t use UUIDs, use this
instead of user_id().
Sourcepub fn require_subject(&self) -> Result<&str>
pub fn require_subject(&self) -> Result<&str>
Like require_user_id() but returns the raw subject string for non-UUID providers.
Sourcepub fn principal_id(&self) -> Option<String>
pub fn principal_id(&self) -> Option<String>
Get a stable principal identifier for access control and cache scoping.
Prefers the raw JWT sub claim and falls back to UUID user_id.
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 moreAuto 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,
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 more