stackure 1.20261013.90

Stackure for Rust: passwordless auth for B2B apps as tower middleware for axum, tonic and hyper.
Documentation
//! Types returned by the Stackure SDK.

use serde::{Deserialize, Serialize};

/// An authenticated Stackure user.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct User {
    /// Unique identifier for the user.
    pub user_id: String,
    /// Identifier of the organization the user belongs to.
    pub account_id: String,
    /// User's email address.
    pub user_email: String,
    /// User's first name.
    pub user_first_name: String,
    /// User's last name.
    pub user_last_name: String,
    /// Whether the user is an app admin or owner in their Stackure
    /// organization, in charge of its apps. What that means in the app is up
    /// to the app.
    #[serde(default)]
    pub user_is_app_admin: bool,
    /// The Stackure teams the user belongs to in their organization, empty
    /// when none.
    #[serde(default)]
    pub user_teams: Vec<Team>,
}

/// A Stackure team.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Team {
    /// Unique identifier for the team.
    pub team_id: String,
    /// Team name.
    pub team_name: String,
}

/// A user listed by [`crate::directory_users`].
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DirectoryUser {
    /// Unique identifier for the user.
    pub user_id: String,
    /// User's email address.
    pub user_email: String,
    /// User's first name.
    pub user_first_name: String,
    /// User's last name.
    pub user_last_name: String,
}

/// Options for [`crate::directory_users`] and [`crate::directory_teams`].
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct DirectoryOptions {
    /// Search text, matching a user's name, email and job title, or a team's name.
    pub query: Option<String>,
    /// `next_cursor` from the previous page.
    pub cursor: Option<String>,
    /// Page size: 100 by default, 200 at most.
    pub limit: Option<u32>,
    /// Only these IDs that can open the app, up to 200, to check or name
    /// people and teams you already store.
    pub ids: Vec<String>,
}

/// One page from [`crate::directory_users`] or [`crate::directory_teams`],
/// sorted by name.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DirectoryPage<T> {
    /// The users or teams on this page.
    pub items: Vec<T>,
    /// Pass as `cursor` to get the next page; `None` on the last one.
    pub next_cursor: Option<String>,
    /// Total matches, on the first page when there are 10,000 or fewer.
    pub total: Option<u64>,
}

/// Successful [`crate::send_magic_link`] response.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MagicLinkResponse {
    /// Human-readable confirmation from the API.
    pub message: String,
}

/// Why a [`crate::verify`] call did not authenticate.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct VerifyError {
    /// HTTP status code: 401 or 500.
    pub code: u16,
    /// Human-readable message.
    pub message: String,
    /// Where to send an unauthenticated browser to sign in.
    #[serde(default)]
    pub sign_in_url: String,
}

/// Outcome of a [`crate::verify`] call.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct VerifyResult {
    /// Whether the request carries a valid session.
    pub authenticated: bool,
    /// The user, when authenticated.
    pub user: Option<User>,
    /// Populated when `authenticated` is `false`.
    pub error: Option<VerifyError>,
}

/// Raw [`crate::validate_session`] response.
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Session {
    /// Whether Stackure recognized the session.
    #[serde(default)]
    pub authenticated: bool,
    /// The user, when authenticated.
    #[serde(default)]
    pub user: Option<User>,
    /// Where to send the browser to sign in, when not.
    #[serde(default)]
    pub sign_in_url: String,
}