APIKeyService (services/api_key_service.py)

openrag · src/services/api_key_service.py · python · Apache-2.0
auth

APIKeyService manages creation, hashing, and storage of user API keys for public API authentication.

# Source: https://github.com/langflow-ai/openrag | 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.
"""
API Key Service for managing user API keys for public API authentication.
"""

import hashlib
import hmac
import secrets
from datetime import UTC, datetime
from typing import Any

from config.settings import API_KEYS_INDEX_NAME
from utils.logging_config import get_logger

logger = get_logger(__name__)
API_KEY_HASH_PREFIX = "hmac-sha256:"


class APIKeyService:
    """Service for managing user API keys for public API authentication."""

    def __init__(self, session_manager=None):
        self.session_manager = session_manager

    def _generate_api_key(self) -> tuple[str, str, 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