CMDCGateway.Plugs.Auth (cmdc_gateway v0.4.0)

Copy Markdown View Source

API Key 校验 Plug。

从请求头 X-API-KeyAuthorization: Bearer <key> 中提取 API Key, 校验后写入 conn.assigns.api_keyconn.assigns.tenant_id

配置

通过 Application env 配置(config :cmdc_gateway, CMDCGateway.Plugs.Auth):

  • :api_keys — 合法 Key 列表或 key → tenant_id 映射
    • ["key1", "key2"] — 所有 Key 归属 "default" 租户
    • %{"key1" => "tenant_a", "key2" => "tenant_b"} — 按 Key 指定租户
  • :skip_auth_paths — 不需要认证的路径列表,默认 ["/healthz"]