Skip to main content

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

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.1.0.tar.gz (5.2 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.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for huudis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b2a6a75cb9f5d358a7f0277aed4cdff48c86f83ea3b83564552d504ff37914f
MD5 099058ca1fcf0c958f79eebb765be724
BLAKE2b-256 4c270d25ba2334f0703f9e78f788551cd631b0b9cdf31d7a292144f0f7f18546

See more details on using hashes here.

File details

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

File metadata

  • Download URL: huudis-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2006d581cccffc09273b154e52899fb8c7c424a83e427d0fff75d92fa1f6dbcf
MD5 a4405654680f0a8f6bed2cd3a00782e1
BLAKE2b-256 871204067175255a52b12631554b806ac83182fce794e3d2002aa9200a009c88

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