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.1.tar.gz (7.2 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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ngits_drf_cube_proxy-1.0.1.tar.gz
  • Upload date:
  • Size: 7.2 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.1.tar.gz
Algorithm Hash digest
SHA256 d1c821a73e9144b315080f04c0ef0cd891d7ba8ca11490c6bd00ea2624ad1300
MD5 a4ae6c4e26f98c48df11f02f8a99a8b7
BLAKE2b-256 0600de776788d36d80ac889137521ccfd000904371606c7dd1fcb8a6ce2c7dca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ngits_drf_cube_proxy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c796d12cf34841118d4040b893e93b2da3b9ca5e12fcaad7c3aa128af642ee8
MD5 d9cf0e5da912ea41d936695cdae84f9c
BLAKE2b-256 2c8d1f9f974c14864fd4f63736b5da3651885268a3a75d10749713dfef1a94d5

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