View as Markdown

Quickstart#

Protect an endpoint, see it refuse an agent that has no approval, then approve one yourself.

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

Install the SDK#

The packages are in private preview and not on public registries yet. The "Install" section of your language's guide has the commands for the preview: Python, JavaScript, Go, Java, C#, PHP, Ruby, Rust.

Describe the endpoint#

One line says what the endpoint lets an agent do (notes:read), how serious it is, and which resource it touches. One sentence says what the person will sign. Only your app writes that sentence.

Run it and call it without approval#

The answer is 401 with a problem document and a challenge that an agent understands:

curl -i http://localhost:3000/notes
HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json
WWW-Authenticate: AllowedBy realm="localhost:3000", error="passport_required"

Let an agent call it#

An agent shows its passport, is told that an approval is missing, asks the person through its node, and tries again. You can watch that whole conversation, and take the person's place, on Try it live.

Next#