Skip to main content

Python client for the Identora authorizer (OIDC + RBAC)

Project description

cl4im

Python client for the Identora authorizer — handles app authentication, JWT validation, permission checking and automatic operation sync.

Installation

pip install cl4im
# With FastAPI support
pip install "cl4im[fastapi]"

Quick start with FastAPI

from fastapi import FastAPI, Request
from cl4im.adapters.fastapi import Cl4im, operation

app = FastAPI()

cl4im = Cl4im(
    app,
    authorizer_url="http://localhost:4000/api",
    app_id="your-app-uuid",
    secret="your-app-secret",
)


@app.get("/public")
@operation(id="public.info", level="public")
async def public_info():
    """Anyone can call this — no token needed."""
    return {"message": "Hello, world!"}


@app.get("/items")
@operation(id="items.list", level="private")
async def list_items(request: Request):
    """Requires any authenticated user (token with non-empty groups)."""
    user = request.state.user  # TokenClaims
    return {"user": user.sub, "items": []}


@app.delete("/items/{item_id}")
@operation(id="items.delete", level="protected")
async def delete_item(item_id: str, request: Request):
    """Requires a user whose group has explicit permission for items.delete."""
    return {"deleted": item_id}

Standalone client

import asyncio
from cl4im import Cl4imClient, OperationDescriptor

client = Cl4imClient(
    authorizer_url="http://localhost:4000/api",
    app_id="your-app-uuid",
    secret="your-app-secret",
)

client.register_operation(
    OperationDescriptor(identifier="items.list", method="read", level="private")
)

async def main():
    await client.startup()

    # Validate a token from an incoming request
    claims = await client.validate_token("<bearer-token>")

    # Check whether the token has permission
    allowed = client.check_permission(claims, "items.list", "read")
    print(f"Allowed: {allowed}")

asyncio.run(main())

Operation levels

Level Who can access
public Everyone — no token required
private Any authenticated user (token with at least one group)
protected Only users whose groups intersect the operation's allowed_groups

Method auto-detection

The @operation decorator infers the method from the function name:

Function name prefix/keyword Detected method
get_, list_, fetch_, read_ read
delete_, remove_, destroy_ delete
contains stream, subscribe, watch stream
anything else write

Configuration

Parameter Description
authorizer_url Base URL of Identora, including the API prefix (e.g. http://host/api)
app_id UUID of the app registered in auth.apps
secret Plain-text app secret (never committed — use env vars)
import os
from cl4im.adapters.fastapi import Cl4im

cl4im = Cl4im(
    app,
    authorizer_url=os.environ["AUTHORIZER_URL"],
    app_id=os.environ["APP_ID"],
    secret=os.environ["APP_SECRET"],
)

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

cl4im-0.2.4.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

cl4im-0.2.4-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file cl4im-0.2.4.tar.gz.

File metadata

  • Download URL: cl4im-0.2.4.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cl4im-0.2.4.tar.gz
Algorithm Hash digest
SHA256 073161b345a222c80a067e7334c7fb4c1b116cad95c9bf1c61c7e656c80dccb8
MD5 e21e1920cb30dd11b4202998e956d18a
BLAKE2b-256 13d8de969a9fee5d3f250edf896b6c7d8a291c32f34cd40d76a74013cb5c7c20

See more details on using hashes here.

File details

Details for the file cl4im-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: cl4im-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cl4im-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7ed3be139d0ef98b77b15161f6d4481465517b2aae4d0614a673a5b7734e5042
MD5 ba166d819e70c8b3a73bdef1d7165ab0
BLAKE2b-256 9f5fd4a02c30b16ed9bb55432a81f0b913f5bd4b76a49dd03f079c6c2f9e6988

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