# API authentication and permissions `/api/v1/` uses bearer personal access tokens/OAuth tokens; `food/api.py` contains the scope/ownership helpers and `food/oauth_pat.py` handles PATs. `/api/v1/auth/whoami/` validates a token for the MCP process. OAuth authorization and token routes come from django-oauth-toolkit plus `food/oauth_authorize.py`; scopes are declared in `tasksnest/settings.py`: `food:read/write`, `inventory:read/write`, `journal:read/write`, and `dietary_preferences:read/write`. Scope checks do not replace row ownership checks. Browser views use Django sessions and CSRF. `planner/middleware_demo.py` blocks privileged demo paths and OAuth exchanges and rate limits demo writes; the account is identified by `UserSettings.is_demo`. `food/api_middleware.py` makes fallback API errors JSON. The OpenAPI document at `/api/v1/schema/` declares common 400, 401, 403 and 404 responses, but some newer paths may not have full per-field schema coverage. Confirm exact method, validation and pagination in the view and tests before integrating. The API uses `Idempotency-Key` for many writes. MCP tool descriptions request clear user intent for destructive or consequential actions; API enforcement is the actual boundary. Dietary conflicts require explicit confirmation at write boundaries where implemented. See [MCP](../mcp/overview.md).