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.0.tar.gz (16.3 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.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cl4im-0.2.0.tar.gz
  • Upload date:
  • Size: 16.3 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.0.tar.gz
Algorithm Hash digest
SHA256 482071f10c72e88548749d0dfd7178aff99dffe33eaf0128130991ccfb759f25
MD5 6fa78bc8bf8edfec2b8f9818856d03a8
BLAKE2b-256 805d60e2ec60ed21e68035160ab07758af035c88584a37d88f2368c21dbe4277

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cl4im-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59467abbb9fbc410016092923e7ce22aec3876a84f38d087306da8e20df6f590
MD5 1ca91d7b79dbf9cac900a6d3653c5256
BLAKE2b-256 33781feff96a68fbe1fefaf03a60db962c2712d11fd19941e6a4c6982ac7bbb9

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