Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

1009 B
Raw Blame
import type { ApiAuth } from '@/openapi/operation';

export const securitySchemes = {
  bearerAuth: {
    type: 'http' as const,
    scheme: 'bearer',
    bearerFormat: 'JWT',
    description:
      'Token returned by POST /api/auth/login, or an API key (`umami_…`) created under Settings → API keys (self-hosted only).',
  },
  shareToken: {
    type: 'apiKey' as const,
    in: 'header' as const,
    name: 'x-umami-share-token',
    description: 'Signed token returned by a share endpoint.',
  },
  shareContext: {
    type: 'apiKey' as const,
    in: 'header' as const,
    name: 'x-umami-share-context',
    description: 'Required context header when authenticating with a share token.',
  },
};

export function getSecurityRequirements(auth: ApiAuth) {
  if (auth === 'none') {
    return [];
  }

  const requirements: Record<string, string[]>[] = [{ bearerAuth: [] }];

  if (auth === 'bearer-or-share') {
    requirements.push({ shareToken: [], shareContext: [] });
  }

  return requirements;
}