Let the person withdraw#
The person takes an approval back on their node; your app refuses it from the next refresh.
| 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. |
routes.append(route("GET", "/export", "notes:export", level=1, resource="note:*", summary="Export your notes"))
templates["notes:export"] = "Export your notes"
@app.get("/export")
def export():
# Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
return {"approval": g.allowedby.gid, "notes": notes.list(g.allowedby.human_id)}routes.push(route("GET", "/export", "notes:export", { level: 1, resource: "note:*", summary: "Export your notes" }));
templates["notes:export"] = "Export your notes";
api.get("/export", (req, res) => {
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
const person = req.allowedby.humanId;
if (person === null) return res.status(403).json({ error: "no person at level 0" }); // level 0: no person to key by
res.json({ approval: req.allowedby.gid, notes: notes.list(person) });
});routes = append(routes, allowedby.Route{Method: "GET", Path: "/export", Capability: "notes:export",
Class: allowedby.Read, Level: 1, Resource: "note:*", Summary: "Export your notes"})
templates["notes:export"] = allowedby.Text("Export your notes")
mux.HandleFunc("GET /export", func(w http.ResponseWriter, r *http.Request) {
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
who, _ := allowedby.ContextFrom(r.Context())
me, ok := who.Human() // false at level 0: an agent calls, with no person to keep data for
if !ok {
writeJSON(w, http.StatusForbidden, map[string]string{"error": "no person at level 0"})
return
}
writeJSON(w, http.StatusOK, map[string]any{"approval": who.GID, "notes": notes.List(me)})
})@Bean
AllowedByCustomizer withdraw() {
return aby -> aby
.route(Route.get("/export").capability("notes:export").level(1).resource("note:*")
.summary("Export your notes"))
.template("notes:export", "Export your notes");
}
@GetMapping("/export")
Map<String, Object> export(@AllowedByContext Context ctx) {
String person = ctx.getHumanId();
if (person == null) { // level 0: no person, and never a key
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "no person at level 0");
}
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
return Map.of("approval", ctx.getGid(), "notes", notes.list(person));
}routes.Add(Route("GET", "/export", "notes:export", level: 1, resource: "note:*", summary: "Export your notes"));
templates["notes:export"] = "Export your notes";
app.MapGet("/export", (AllowedByContext ctx) =>
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
new { approval = ctx.Gid, notes = notes.List(Person(ctx)) });$routes[] = route('GET', '/export', 'notes:export', level: 1, resource: 'note:*', summary: 'Export your notes');
$templates['notes:export'] = 'Export your notes';
$app->get('/export', function (Request $request, Response $response) use ($json, $notes) {
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
$context = $request->getAttribute('allowedby.context');
return $json($response, ['approval' => $context->gid, 'notes' => $notes->list($context->humanId ?? throw new LogicException('no person at level 0'))]);
});ROUTES << AllowedBy.route("GET", "/export", "notes:export", level: 1, resource: "note:*", summary: "Export your notes")
TEMPLATES["notes:export"] = "Export your notes"
get "/export" do
# Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
context = env["allowedby.context"]
person = context.human_id or halt 403, { error: "no person: this route needs one" }.to_json
{ approval: context.gid, notes: notes.list(person) }.to_json
endlet aby = aby
.route(
Route::get("/export").capability("notes:export").level(1).resource("note:*").summary("Export your notes"),
)
.template("notes:export", "Export your notes");
let app = app.route("/export", get(export));
async fn export(ctx: AllowedByContext, State(notes): State<Notes>) -> Json<Value> {
// Once the person withdraws this approval, the SDK answers 401 revoked. Keep its id with what you do.
Json(json!({"approval": ctx.gid, "notes": notes.list(&ctx.human_id)}))
}What the test proves#
- the person approves, and the app knows which approval it served
- the person withdraws it: from the next refresh, 401 revoked
- their other approvals still work
- asked again, the person may approve again: a new approval, 200