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.2.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.2-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tahportal_sso-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a0fe14a1652cade5d7a61ddc8133e75cf15fe7a6fa9a6d866170f03a7bd4bec3
MD5 45af0f40cff218dac31e59931ca8c0df
BLAKE2b-256 5251e546a3b4ba6e0985ac4152aad785ca606f7554d39fd157be3156a56abde7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tahportal_sso-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b6ec099f82ebc0afc2ba2a298d2246cefb40d8e191a607c52660ad853025bca
MD5 75201c6395f6a59bea72b571205dbfb5
BLAKE2b-256 86f1ae71c0887b43420eed423a4e217de8c88be02868383c931928c598c191c3

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