Nod management API for Python
A client for each realm's management API (<issuer>/api/v1), standard library only: nothing to install beside it. Python 3.9 or later.
from nod_management import Management, NodError
m = Management("https://auth.example.com/acme", client_id="ops", client_secret=SECRET)
alice = m.users.create("alice", email="alice@example.com")
m.organizations.add_member("initech", alice["id"])
for u in m.users.all(): # follows the cursor for you
print(u["username"])
for e in m.logs.all(type="signin.failure"): # the security log, oldest first
print(e["time"], e.get("username"), e.get("ip"))
try:
m.users.create("x")
except NodError as e:
print(e.status, e.error, e.description)
- Credentials: a machine client of the realm granted management scopes (
nod client grant acme ops <issuer>/api --scope users:read …). The client gets and renews its own token. - Covers the realm (its sign-in pages' custom text,
realm.set_text, included), users, clients, roles, organizations (members, roles, connections, invitations), the realm's connections (outside providers: OpenID Connect, GitHub, OAuth 2.0, LDAP, SAML), fine-grained authorization (batch checks included), the waitlist (waitlist.list,waitlist.all,waitlist.admit) and the security log.m.request(method, path, query=…, body=…)reaches anything else. Responses are the API's JSON as dicts, shaped as indocs/api/management.openapi.json.
- Nods and ceilings: the nod-level calls (
realm.update,clients.update,clients.delete,users.update,users.block/unblock,waitlist.admit) takeapproval=, sent asNod-Approval. A call that needs a person's nod raisesNodRequired(aNodError) withchallenge(theWWW-Authenticatevalue),issuerandauthorization_details; one past a standing ceiling raisesLimitReachedwithretry_afterin seconds.
Tests run the client against a real server on a throwaway PostgreSQL: python3 -m unittest discover -v -s tests -t . (set HARPORA_BIN or NOD_BIN to use an already built harpora); python3 -m unittest -v tests.test_offline needs no server. Not published yet: publishing under a package name is a person's decision.
Billing
m.billing covers plans (plans, plan, set_plan, delete_plan, add_price), an organization's state (organization, set_organization; a PUT older than the stored as_of_ms answers "stale": True), the customer list (organizations for a page, all_organizations for every page), checkout, portal and sync (health).
m.billing.set_plan("pro", ["sso", "audit_log"], display_name="Pro")
m.billing.add_price("pro", 900, "eur", "month")
url = m.billing.checkout("initech", "pro", "https://app.example.com/ok", "https://app.example.com/no")["url"]
In your app, org_plan(claims), org_features(claims) and has_feature(claims, "sso") read org_plan and org_features from a token's decoded claims; no org_plan is the free tier (None, no features). They verify nothing: verify the access or ID token first.