pub struct Identity { /* private fields */ }Expand description
The authenticated caller of the current request: an object (a type and
an id) — never a set like group:eng#member.
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn new(subject: impl AsRef<str>, source: &'static str) -> Identity
pub fn new(subject: impl AsRef<str>, source: &'static str) -> Identity
A caller you name in code: "service:billing" (a type, :, an id)
or a bare id, which gets the type user. source says who vouched
("jwt", "oidc", "saml", "basic", "forward", "mcp", or your
own). For a value that came from outside, use Identity::user.
Sourcepub fn user(id: &str, source: &'static str) -> Option<Identity>
pub fn user(id: &str, source: &'static str) -> Option<Identity>
The user whose id is id exactly — what authenticators use for a
value from a token, a header or a login. A : stays part of the id
(user:a:b). None when id can’t name an object: empty, over 256
characters, or holding #, @, a space or a control character —
so a token whose sub is group:eng#member can’t pass as that group.
Sourcepub fn with_claims(self, claims: impl AsRef<str>) -> Identity
pub fn with_claims(self, claims: impl AsRef<str>) -> Identity
The same, carrying the token’s or assertion’s claims (a JSON object).
Sourcepub fn from_claims(
claims: &str,
claim: &str,
source: &'static str,
) -> Option<Identity>
pub fn from_claims( claims: &str, claim: &str, source: &'static str, ) -> Option<Identity>
An identity from a JSON claims object: its claim ("sub" usually) as
the subject id. None when the claim is missing or not a string.
Sourcepub fn current() -> Option<Identity>
pub fn current() -> Option<Identity>
The caller of the request being served on this thread or task.
Sourcepub fn subject_type(&self) -> &str
pub fn subject_type(&self) -> &str
The type part of the subject (user).
Sourcepub fn subject_id(&self) -> &str
pub fn subject_id(&self) -> &str
The id part of the subject (alice).
Sourcepub fn as_subject(&self) -> Subject
pub fn as_subject(&self) -> Subject
The caller as a tuple subject: an object, never a set.
Trait Implementations§
impl Eq for Identity
impl StructuralPartialEq for Identity
Auto Trait Implementations§
impl Freeze for Identity
impl RefUnwindSafe for Identity
impl Send for Identity
impl Sync for Identity
impl Unpin for Identity
impl UnsafeUnpin for Identity
impl UnwindSafe for Identity
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.