Skip to main content

RequestUser

Trait RequestUser 

Source
pub trait RequestUser {
    // Required method
    fn current_user(&self) -> Option<&CurrentUser>;

    // Provided methods
    fn user_id(&self) -> Option<&str> { ... }
    fn user_name(&self) -> Option<&str> { ... }
    fn user_email(&self) -> Option<&str> { ... }
    fn tenant_id(&self) -> Option<&str> { ... }
    fn roles(&self) -> &[String] { ... }
    fn is_in_role(&self, role: &str) -> bool { ... }
    fn require_user(&self) -> Result<&CurrentUser, Error> { ... }
}
Expand description

Convenience accessors for a request that carries a CurrentUser.

#[derive(WebxRequestMeta)] implements this automatically when the struct has a #[fromclaim] field of type CurrentUser or Option<CurrentUser>.

Required Methods§

Source

fn current_user(&self) -> Option<&CurrentUser>

The authenticated identity, or None for an anonymous request.

Provided Methods§

Source

fn user_id(&self) -> Option<&str>

The subject identifier, or None when anonymous.

Source

fn user_name(&self) -> Option<&str>

The display name, or None when anonymous.

Source

fn user_email(&self) -> Option<&str>

The email address, or None when anonymous.

Source

fn tenant_id(&self) -> Option<&str>

The tenant identifier, or None when anonymous.

Source

fn roles(&self) -> &[String]

The roles of the authenticated user (empty when anonymous).

Source

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

Whether the authenticated user has role.

Source

fn require_user(&self) -> Result<&CurrentUser, Error>

The identity, or 401 Unauthorized when the request is anonymous.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§