Skip to main content

Official Python SDK for Huudis — email/social/MFA + fine-grained authorization + webhook signature verification.

Project description

huudis (Python)

Official Python SDK for Huudis. Works with FastAPI, Flask, Django, or anything else that speaks WSGI/ASGI.

Install

pip install huudis

Quickstart

Set env vars (or pass them to the client):

HUUDIS_ISSUER=https://huudis.com
HUUDIS_AUDIENCE=oc_your_client_id
HUUDIS_CLIENT_ID=oc_your_client_id
HUUDIS_CLIENT_SECRET=cs_...   # omit for public clients (PKCE)

Verify an access token

from fastapi import FastAPI, Header, HTTPException
from huudis import verify_access_token, HuudisAuthError

app = FastAPI()

@app.get("/me")
def me(authorization: str = Header(...)):
    try:
        claims = verify_access_token(authorization)
    except HuudisAuthError as e:
        raise HTTPException(401, detail=e.message)
    return {"user_id": claims.sub, "email": claims.email}

OIDC sign-in flow

from huudis import HuudisClient

huudis = HuudisClient()

# Step 1: redirect the user
url = huudis.authorization_url(
    redirect_uri="https://yourapp.com/callback",
    state=session["state"],
    code_challenge=session["pkce_challenge"],
)

# Step 2: exchange the code
tokens = huudis.exchange_code(
    code=request.args["code"],
    redirect_uri="https://yourapp.com/callback",
    code_verifier=session["pkce_verifier"],
)
userinfo = huudis.userinfo(tokens["access_token"])

Authorization check

result = huudis.authz_check(
    access_token=token,
    principal={"type": "user", "id": claims.sub, "accountId": claims.account_id},
    action="plugipay:DeleteInvoice",
    resource="forjio:plugipay::acc_.../invoice/inv_9F8",
)
if not result["allow"]:
    raise HTTPException(403, detail=result.get("reason"))

Types

Name Description
verify_access_token(header_or_token, *, issuer=None, audience=None, require_mfa=False) Module-level convenience — reads HUUDIS_ISSUER / HUUDIS_AUDIENCE from env.
HuudisClient(issuer=..., client_id=..., client_secret=..., audience=..., api_base=...) Full surface. Use as a context manager (with HuudisClient() as huudis:) or call .close().
HuudisClaims Dataclass returned by verification — sub, email, account_id, scope, mfa_verified, etc.
HuudisAuthError Raised on any failure; carries .code + .message.

JWKS is cached in-process via PyJWT's PyJWKClient.

Docs

License

MIT

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

huudis-0.2.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

huudis-0.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: huudis-0.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for huudis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b8513d0af2179950a84f91d330f0b9722c5b5f2c7826b3c76b9c4b833597f72
MD5 7b1168cf09678bb11761c8dbbef60061
BLAKE2b-256 0cebdf12145d25781569d044e0fd052fc15935000fddf6c24fd5faa48f0d099b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: huudis-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for huudis-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ee5b41ff5a71da370b6597e501ace6e7c401910cd1ccabeff8a1f92d408dba0
MD5 6d090538420f15d66a492e93b393674a
BLAKE2b-256 4fe4e72fa185c666ebcb39342a897d47f74c268298a4bbad9b868f18e46c0c66

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