entropy-auth 2026.7.31

Authentication and authorization for Entropy Softworks server and API projects
//! Standard OIDC claims shared between ID tokens and `UserInfo` responses.
//!
//! The `OpenID` Connect Core 1.0 specification defines a set of "standard
//! claims" (§5.1) that appear in both ID tokens and `UserInfo` endpoint
//! responses. This module extracts those fields into a single
//! [`StandardClaims`] struct to avoid duplication.

/// Standard OIDC claims common to ID tokens and `UserInfo` responses.
///
/// Contains the optional profile-level claims defined by `OpenID` Connect
/// Core 1.0 §5.1. The required `sub` claim is stored separately in the
/// parent type because its presence requirements differ (always required
/// in `UserInfo`, but extracted from `JwtClaims` for ID tokens).
#[derive(Debug, Clone)]
pub(crate) struct StandardClaims {
    /// User's full name.
    pub(crate) name: Option<String>,
    /// User's email address.
    pub(crate) email: Option<String>,
    /// Whether the user's email has been verified.
    pub(crate) email_verified: Option<bool>,
    /// User's preferred username or display name.
    pub(crate) preferred_username: Option<String>,
    /// URL of the user's profile picture.
    pub(crate) picture: Option<String>,
}

impl StandardClaims {
    /// Creates a new `StandardClaims` with the given optional fields.
    pub(crate) fn new(
        name: Option<String>,
        email: Option<String>,
        email_verified: Option<bool>,
        preferred_username: Option<String>,
        picture: Option<String>,
    ) -> Self {
        Self {
            name,
            email,
            email_verified,
            preferred_username,
            picture,
        }
    }

    /// Returns the user's full name, if present.
    #[must_use]
    #[inline]
    pub(crate) fn name(&self) -> Option<&str> {
        self.name.as_deref()
    }

    /// Returns the user's email address, if present.
    #[must_use]
    #[inline]
    pub(crate) fn email(&self) -> Option<&str> {
        self.email.as_deref()
    }

    /// Returns whether the user's email has been verified, if present.
    #[must_use]
    #[inline]
    pub(crate) fn email_verified(&self) -> Option<bool> {
        self.email_verified
    }

    /// Returns the user's preferred username, if present.
    #[must_use]
    #[inline]
    pub(crate) fn preferred_username(&self) -> Option<&str> {
        self.preferred_username.as_deref()
    }

    /// Returns the URL of the user's profile picture, if present.
    #[must_use]
    #[inline]
    pub(crate) fn picture(&self) -> Option<&str> {
        self.picture.as_deref()
    }
}