A utility to distinguish between JWT and opaque bearer tokens. Use this in authentication middleware to validate token formats before processing.
// Source: https://github.com/constructorfabric/gears-rust | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
//! Token type detection — distinguishes JWT tokens from opaque tokens.
//!
//! A JWT is identified by exactly three dot-separated segments.
//! The first two segments (header + payload) must be non-empty.
//! The signature segment may be empty for unsecured tokens (`alg: none`).
//! All other bearer tokens are treated as opaque and rejected by auth policy.
use toolkit_macros::domain_model;
/// The detected type of a bearer token.
#[domain_model]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TokenType {
/// A JSON Web Token (header.payload.signature format).
Jwt,
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key