Skip to main content

Read the signed ShinyHub identity a Shiny/Streamlit/Dash app receives, in one call.

Project description

shinyhub-identity

Read the signed identity ShinyHub forwards to your app, in one call. No per-app JWT plumbing.

ShinyHub injects a short-lived, per-app HS256 JWT (X-Shinyhub-Identity-Token) into every request it proxies, and hands your app its verification key via SHINYHUB_IDENTITY_KEY and SHINYHUB_APP_SLUG. This package verifies that token and returns the identity.

pip install shinyhub-identity
# or: uv add shinyhub-identity

Use it

from shinyhub_identity import current_user

def server(input, output, session):
    user = current_user(session.http_conn.headers)   # None when anonymous
    if user is None:
        ...  # logged-out visitor
    elif "platform-admins" in user.groups:
        ...  # gate admin features on the VERIFIED groups

current_user(headers) returns an Identity (user_id, username, role, email, groups, groups_truncated, and the raw claims) or None. email is "" unless the deployment's forward-auth SSO asserts one. It works with any header mapping - Shiny for Python's session.http_conn.headers, a Starlette/Flask request's headers, or a plain dict.

Every failure is anonymous, never a crash. No token, bad signature, wrong audience/issuer, an expired token, or no ShinyHub in front at all (running the app locally) all return None, so your app stays testable without SSO.

current_user reads SHINYHUB_IDENTITY_KEY/SHINYHUB_APP_SLUG from the environment by default; pass key=/slug= explicitly for tests.

Why verify, not just read the plain headers?

ShinyHub also forwards convenience plain headers (X-Shinyhub-User, -Role, -Groups, ...) and strips any client-supplied ones. But app processes listen on host-local ports, so a co-located process can bypass the proxy and forge plain headers. Anything that gates access must verify the token - which is exactly what this package does. See ShinyHub's docs/identity.md for the full trust model.

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

shinyhub_identity-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

shinyhub_identity-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file shinyhub_identity-0.1.0.tar.gz.

File metadata

  • Download URL: shinyhub_identity-0.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shinyhub_identity-0.1.0.tar.gz
Algorithm Hash digest
SHA256 60b3ab8bb164079840b19b0a0e9f023de89b08a792402f17abea1e9e8c04e874
MD5 dc6be916c7b488536e2aacceb19e111a
BLAKE2b-256 f8c7278dac08cf1022dc279acade3dbf45a79469dde4e471d991c22bb3e8f5eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for shinyhub_identity-0.1.0.tar.gz:

Publisher: release.yml on rvben/shinyhub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shinyhub_identity-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shinyhub_identity-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25fd107b23825584392012a0a31988feb25c51675a7ff565517306e4a996c08c
MD5 07699f13a52636c9ddb915cfc6b2a88c
BLAKE2b-256 720a1f4f5e6c1ebb948529047e57e802b3aee70cf0ebb3868be3b3cf2ba8c7eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for shinyhub_identity-0.1.0-py3-none-any.whl:

Publisher: release.yml on rvben/shinyhub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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