View as Markdown

Quickstart#

A whole app that lets agents in with the person's approval.

Level 1: A person approves with a passkey.
Class read: Nothing changes. The approval can be reused until it ends or the person withdraws it.
import os

from flask import Flask, g

from allowedby import route
from allowedby.flask import AllowedBy

app = Flask(__name__)
app.config["ALLOWEDBY"] = {
    "origin": os.environ["ALLOWEDBY_ORIGIN"],  # your app's public URL
    "node": os.environ["ALLOWEDBY_NODE"],  # the node you trust: people approve there
    "org": {"legal_name": "Notes Ltd", "country": "FR"},
    "routes": [route("GET", "/notes", "notes:read", level=1, resource="note:*")],
    "templates": {"notes:read": "Read your notes"},  # what the person approves
}
AllowedBy(app)


@app.get("/notes")
def list_notes():
    return {"notes": [], "person": g.allowedby.human_id}

Run in 8 languages on this version. See the results

What the test proves#

  • a plain request is refused: 401 passport_required, with the AllowedBy challenge
  • nothing else is served: another method or path is a 4xx
  • an agent asks, the person approves once with a passkey, and the app answers 200