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.2.tar.gz (16.2 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.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cl4im-0.2.2.tar.gz
  • Upload date:
  • Size: 16.2 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.2.tar.gz
Algorithm Hash digest
SHA256 da5c7f5413a520a46bbbd16a94b787f65f1122895b1bbddb2e129322d9344a74
MD5 c5bfae43b5c0ab52cccb17f18ee7393c
BLAKE2b-256 99bb06ce0ec6a4b4199debde4e12dac8525d75b14363f35a8078ec8b3638c4b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cl4im-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24709565db372d901d8b6e6384579706b4eec19ed74a2be1c750f6be23ae03f3
MD5 6b8e3c3572c8711ccf0c7a07b75e4581
BLAKE2b-256 0d8f23ee4a0fff82ecd24f0bcee76ae3f3cfab99a2f48cbd129ca4440884b631

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