Skip to main content

AuthIdentity

Struct AuthIdentity 

Source
pub struct AuthIdentity {
    pub subject: String,
    pub roles: Vec<String>,
    pub claims: BTreeMap<String, Value>,
}
Expand description

Authentication Identity

Represents an authenticated user’s identity within the NestForge framework. Contains the subject (typically user ID), roles, and additional custom claims.

§Fields

  • subject: The unique identifier for the user (e.g., user ID, email)
  • roles: List of role names the user possesses
  • claims: Additional key-value pairs for custom authentication data

§Usage

This type is automatically populated by the framework’s authentication middleware and can be accessed in handlers via the AuthUser extractor.

Fields§

§subject: String§roles: Vec<String>§claims: BTreeMap<String, Value>

Implementations§

Source§

impl AuthIdentity

Source

pub fn new(subject: impl Into<String>) -> Self

Creates a new authentication identity.

§Arguments
  • subject: The unique identifier for the user
§Example
let identity = AuthIdentity::new("user-123");
Source

pub fn with_roles<I, S>(self, roles: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Adds roles to the authentication identity.

§Arguments
  • roles: An iterator of role names to assign
Source

pub fn with_claim(self, key: impl Into<String>, value: Value) -> Self

Adds a custom claim to the authentication identity.

§Arguments
  • key: The claim key
  • value: The claim value
Source

pub fn has_role(&self, role: &str) -> bool

Checks if the identity has a specific role.

§Arguments
  • role: The role name to check

Returns true if the role is present in the identity’s roles.

Source

pub fn require_role(&self, role: &str) -> Result<(), HttpException>

Requires a specific role, returning an error if not present.

§Arguments
  • role: The required role name

Returns Ok if the role is present, or a forbidden HttpException if not.

Trait Implementations§

Source§

impl Clone for AuthIdentity

Source§

fn clone(&self) -> AuthIdentity

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuthIdentity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AuthIdentity

Source§

fn default() -> AuthIdentity

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AuthIdentity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AuthIdentity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoInjectableResult<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,