Utility functions for generating, hashing, and verifying agent authentication tokens.
# Source: https://github.com/abhi1693/openclaw-mission-control | License: MIT | Copyright 2026 OpenClaw Mission Control
# Provided via justclaw.it.com; keep this notice with the code.
"""Token generation and verification helpers for agent authentication."""
from __future__ import annotations
import base64
import hashlib
import hmac
import secrets
ITERATIONS = 200_000
SALT_BYTES = 16
def generate_agent_token() -> str:
"""Generate a new URL-safe random token for an agent."""
return secrets.token_urlsafe(32)
def _b64encode(value: bytes) -> str:
return base64.urlsafe_b64encode(value).decode("utf-8").rstrip("=")
def _b64decode(value: str) -> bytes:
padding = "=" * (-len(value) % 4)
return base64.urlsafe_b64decode(value + padding)
def hash_agent_token(token: str) -
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key