Files
apuc 756f40353b Add Django backend, 1C integration, deploy config and API docs
Backend (Django 4.2 + DRF):
- accounts: phone OTP login, JWT, profile, addresses
- catalog: categories, products, images, filters, search, hits/new/related
- orders: creation with Idempotency-Key, stock reservation, status history, cancel
- loyalty: bonus accounts, promo codes, gift certificates
- payments: payment records and YooKassa webhook handling
- content: static pages, banners, site settings
- integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses)
- common: error envelope, pagination, request-id, integration auth, admin dashboard

Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx),
requirements split by environment, OpenAPI contracts for site and 1C, architecture doc.

Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
2026-11-22 21:54:16 +03:00

42 lines
1.3 KiB
Python

import hmac
from django.conf import settings
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.permissions import BasePermission
class IntegrationTokenAuthentication(BaseAuthentication):
"""Authenticates 1C using a shared secret.
The token is accepted either as ``X-Integration-Token`` or as a
``Bearer`` token in the ``Authorization`` header.
"""
def authenticate(self, request):
token = request.headers.get("X-Integration-Token")
if not token:
header = request.headers.get("Authorization", "")
if header.startswith("Bearer "):
token = header[7:].strip()
if not token:
return None
expected = getattr(settings, "INTEGRATION_API_TOKEN", "")
if not expected or not hmac.compare_digest(token, expected):
raise AuthenticationFailed("Invalid integration token")
request.integration_authenticated = True
return (None, None)
def authenticate_header(self, request):
return "Bearer"
class IsIntegrationClient(BasePermission):
"""Allows access only to requests authenticated with the integration token."""
def has_permission(self, request, view):
return bool(getattr(request, "integration_authenticated", False))