Skip to main content

Highly configurable authentication and authorization package wrapping Keycloak

Project description

authflow - Backend Package

Python/FastAPI backend for authflow-stack.

Installation

pip install authflow

Quick Start

from fastapi import FastAPI, Depends
from authflow import AuthFlow, setup_auth
from authflow.dependencies import get_current_user, require_permission

app = FastAPI()

# Initialize from config file
auth = AuthFlow.from_config("authflow.config.yaml")
setup_auth(app, auth, prefix="/api/v1/auth")

# Protected route
@app.get("/api/data")
async def get_data(user = Depends(get_current_user)):
    return {"message": f"Hello {user.username}"}

# Permission-protected route
@app.post("/api/contracts")
@require_permission("contracts:write")
async def create_contract(user = Depends(get_current_user)):
    return {"status": "created"}

Configuration

Create authflow.config.yaml:

provider:
  type: keycloak
  keycloak:
    url: https://keycloak.example.com
    realm: my-realm
    client_id: authflow-client
    client_secret: ${KEYCLOAK_SECRET}

features:
  organizations: true
  teams: true
  email_verification: true

rbac:
  model: role-based
  scopes: [global, organization, team]

Development

pip install -e ".[dev]"
pytest

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

authflow-0.1.2.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

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

authflow-0.1.2-py3-none-any.whl (47.8 kB view details)

Uploaded Python 3

File details

Details for the file authflow-0.1.2.tar.gz.

File metadata

  • Download URL: authflow-0.1.2.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for authflow-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1727c4393c53811280d533d1e2e8aaa4cc70ccf8284e09663d2ec28af7a5e5f0
MD5 885b33727f3e8c7852fc698936cf6bd9
BLAKE2b-256 0662016910994baa51bb6d6659620d574cae8b53013a30d4d715b227fbb8b702

See more details on using hashes here.

File details

Details for the file authflow-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: authflow-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 47.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for authflow-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2b2bd660fcedf0152c37f354227f8bee28b9ae71bed2899ff66b888bb185d0a8
MD5 4b438929f08d5fe1e5dc46fbfd7beaac
BLAKE2b-256 81dc202882536eb61b1b0ad4ac9b3d1b851d758adbbe30daeb39de2a55b49c8e

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