Skip to main content

Cube.js JWT proxy for Django REST Framework

Project description

Server-side proxy for the Cube.js /load endpoint, packaged as a small Django/DRF application. The proxy signs an HS256 JWT per request with an identity value (e.g. a tenant UUID, an organisation id, a project id …) resolved from the authenticated user, so the Cube.js secret never reaches the browser.

Setup

1. Install with pip:

 pip install ngits-drf-cube-proxy

(or ``pip install "ngits-drf-cube-proxy[schemas]"`` for the
drf-spectacular OpenAPI schemas)

2. Update your settings file:

 import os

 INSTALLED_APPS = [
     ...
     "rest_framework",
     "cube_proxy",
 ]

 # Required
 CUBEJS_API_URL = os.environ["CUBEJS_API_URL"]
 CUBEJS_API_SECRET = os.environ["CUBEJS_API_SECRET"]
 CUBE_PROXY_IDENTITY_RESOLVER = "myproject.cube.resolve_identity"

 # Optional
 CUBE_PROXY_PERMISSION_CLASSES = (
     "rest_framework.permissions.IsAuthenticated",
     "myproject.permissions.IsModerator",
 )
 CUBE_PROXY_JWT_CLAIM_NAME = "tenant"                 # default
 CUBE_PROXY_JWT_TTL_HOURS = 24                        # default
 CUBE_PROXY_JWT_ALGORITHM = "HS256"                   # default
 CUBE_PROXY_REQUEST_TIMEOUT = 30                      # default
 CUBE_PROXY_IDENTITY_NOT_FOUND_DETAIL = "Identity could not be resolved."

``CUBE_PROXY_IDENTITY_RESOLVER`` is the dotted path to a callable
``resolve(user) -> str | None``. The returned value is stamped into the
JWT under ``CUBE_PROXY_JWT_CLAIM_NAME`` (default ``tenant``) and becomes
the Cube.js security-context key. Returning ``None`` yields a
``403 {"detail": "Identity could not be resolved."}`` response.

3. Add the URLs:

 from django.urls import include, path

 urlpatterns = [
     ...
     path("cube/", include("cube_proxy.urls")),
 ]

The endpoint is then available at ``/cube/load/`` and accepts both ``GET``
(query-as-URL-params, used by the Cube.js JS SDK for small queries) and
``POST`` (query in body, used for large queries).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ngits_drf_cube_proxy-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ngits_drf_cube_proxy-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ngits_drf_cube_proxy-1.0.0.tar.gz.

File metadata

  • Download URL: ngits_drf_cube_proxy-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for ngits_drf_cube_proxy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 595c8b2a62981b72bdc266fc59ba526feb4833aefec80a663fdf3f4acb6c819b
MD5 bbe0c67fc7404124d0f610a21e9c41f8
BLAKE2b-256 16f87cd40a6051efd26700fc184363c64722a0793480ecf4407be757165e9982

See more details on using hashes here.

File details

Details for the file ngits_drf_cube_proxy-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ngits_drf_cube_proxy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5beff41ef0296974ffcc0958c5e583e31941f4a6ebd7d157e94e09d71ecbe425
MD5 b6a2a1db88e1595363cb25e976026b8d
BLAKE2b-256 d43fd85bfbda5e5ad6e5cab7a3d581c5620a59c5fce8dec77be44454febb338f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page