Skip to main content

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

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.4.tar.gz (53.6 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.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tahportal_sso-1.0.4.tar.gz
  • Upload date:
  • Size: 53.6 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.4.tar.gz
Algorithm Hash digest
SHA256 db83334c452db2cf02cf02451dd3f2b34f11a2e465d68fc1caccafa3a1237083
MD5 ee706eb8081db36d83c4376d3843521f
BLAKE2b-256 385ae743a73cc73586d900e0a92555118085b51eb3ec3af88e2992678931b21d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tahportal_sso-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f5c9006daef84aead559caa5cbb848f43f9728549c1d196edda60acf2083051a
MD5 588088f5fc3712fa690d37c6c1f25a0d
BLAKE2b-256 3def94df3872cbeefa936420b5f046c0d3c97254bb29f8f4838ca15facf5a747

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