auth0-integration 0.6.1

Auth0 client library for M2M token retrieval and JWT validation (RS256)
Documentation
use std::str::FromStr;

use crate::error::AppError;

/// Represents a user role in Auth0.
///
/// The `FromStr` impl accepts case-insensitive short names (`"admin"`, `"super_admin"`, `"worker"`).
/// `as_auth0_name()` returns the exact string stored in Auth0 (`"ADMIN"`, `"SUPER_ADMIN"`, `"WORKER"`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Role {
    Admin,
    SuperAdmin,
    Worker,
}

impl Role {
    /// Returns the role name as stored in Auth0.
    pub fn as_auth0_name(&self) -> &str {
        match self {
            Role::Admin => "ADMIN",
            Role::SuperAdmin => "SUPER_ADMIN",
            Role::Worker => "WORKER",
        }
    }
}

impl FromStr for Role {
    type Err = AppError;

    /// Parses a role from a user-friendly string (case-insensitive).
    ///
    /// Accepted values: `"admin"`, `"super_admin"`, `"worker"`.
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "admin" => Ok(Role::Admin),
            "super_admin" => Ok(Role::SuperAdmin),
            "worker" => Ok(Role::Worker),
            _ => Err(AppError::InvalidRole(s.to_string())),
        }
    }
}