Skip to main content

TAHPortal SSO integration for Python web applications (FastAPI and Flask)

Project description

tahportal-sso

TAHPortal SSO integration package for Python web applications. Connects your product to the TAHPortal identity gateway with minimal setup.

Installation

```bash pip install tahportal-sso

with FastAPI support

pip install tahportal-sso[fastapi]

with Flask support

pip install tahportal-sso[flask] ```

Quick start

Set three environment variables in your product:

```bash TAHPORTAL_URL=https://your-tahportal-domain.com TAHPORTAL_PRODUCT_ID= TAHPORTAL_SESSION_SECRET=<random 64-char hex string> TAHPORTAL_SESSION_TTL=3600 # optional, defaults to 3600 seconds ```

FastAPI

```python from fastapi import FastAPI, Depends from tahportal_sso import TahPortalSSO, TahPortalConfig, SSOUser

config = TahPortalConfig.from_env() sso = TahPortalSSO(config)

app = FastAPI() app.include_router(sso.get_fastapi_router())

@app.get("/dashboard") async def dashboard(user: SSOUser = Depends(sso.require_user)): return {"welcome": user.full_name, "role": user.user_role} ```

Flask

```python from flask import Flask from tahportal_sso import TahPortalSSO, TahPortalConfig

config = TahPortalConfig.from_env() sso = TahPortalSSO(config)

app = Flask(name) sso.init_flask(app)

@app.route("/dashboard") @sso.login_required def dashboard(): user = sso.get_current_user() return {"welcome": user.full_name} ```

How it works

  1. TAHPortal generates a short-lived one-time code when a user launches this product
  2. This package exchanges the code for the user's identity at TAHPortal's /api/sso/exchange endpoint
  3. A local session JWT is created and stored in an httpOnly cookie
  4. All subsequent requests are validated locally — no network call to TAHPortal on every request
  5. When the session expires the user is redirected back to TAHPortal to re-authenticate

Session expiry and access revocation

Sessions expire after TAHPORTAL_SESSION_TTL seconds. When a session expires, the user is redirected to TAHPortal. If their subscription has been revoked, TAHPortal will deny access at that point.

Set a shorter TTL for higher-security products: ```bash TAHPORTAL_SESSION_TTL=900 # 15 minutes ```

License

MIT — Copyright (c) 2026 STOP THE TRAFFIK / Traffik Analysis Hub

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

tahportal_sso-1.0.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

tahportal_sso-1.0.3-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file tahportal_sso-1.0.3.tar.gz.

File metadata

  • Download URL: tahportal_sso-1.0.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for tahportal_sso-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d5a37fea1e220b6de577442f5e7f7a79209bbe879c76551a6fc340001b00bc2a
MD5 63025d17e00ed71d66e08abf5ee5ac11
BLAKE2b-256 4ff85ae2ed106aa6961922112a058834ffee6061bce857d906513b3446dee354

See more details on using hashes here.

File details

Details for the file tahportal_sso-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: tahportal_sso-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for tahportal_sso-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0d0ae325b3babecb50be6433b6df525577793d7548e0e519ae3e953cd07743
MD5 b0304d03fa33d4a416b53641eab4a5f7
BLAKE2b-256 dc980f326daac53cd746e8d3b722836e80b0c8da7d079bd5bbdab4484de63196

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