Vigiora

此页面暂无简体中文版本,以英文显示。

Authentication and scopes自 1.6.4 起

Call API v1 with a scoped API key or a user session, pick the scopes an integration needs, and understand what decides whether a call is allowed.

Every API v1 call needs a credential: an API key for scripts and integrations, or a user session for tools a person signs in to.

Send an API key#

Send the key in a header, either way:

Terminal
curl -s https://yourname.vigiora.com/api/v1/me \
  -H "Authorization: Bearer vgk_xxxxxxxx_xxxxxxxxxxxxxxxx"
 
curl -s https://yourname.vigiora.com/api/v1/me \
  -H "X-API-Key: vgk_xxxxxxxx_xxxxxxxxxxxxxxxx"

A key is never accepted in the URL. If both headers are sent, X-API-Key wins.

GET /api/v1/me tells you who the credential is and which scopes it has:

{
  "user": { "id": 7, "username": "automation", "role": "operator" },
  "auth": { "type": "api_key", "key_id": 12, "scoped": true, "scopes": ["cameras:read", "alerts:write"] }
}

auth.type is api_key, session, or oauth for an AI app that signed in through the MCP server. OAuth tokens work only on the MCP endpoint, never on REST.

Use a user session#

Tools a person signs in to can use the same session as the web app:

Terminal
curl -s -X POST https://yourname.vigiora.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"automation","password":"example-password"}'

Send the returned access_token as Authorization: Bearer <token>. A session has every scope; the user's role and camera permissions still apply. On v1 the token is only accepted in the header, never as ?token=.

Create a scoped key#

Scoped keys are created with POST /api/v1/api-keys, which needs a user session: an API key can never create, list or revoke keys. That stops a leaked key from minting a successor.

  1. Sign in

    Get an access token with POST /api/auth/login (above).

  2. Create the key

    Choose a name, the scopes the integration needs, and optionally an expiry:

    Terminal
    curl -s -X POST https://yourname.vigiora.com/api/v1/api-keys \
      -H "Authorization: Bearer <access token>" \
      -H "Content-Type: application/json" \
      -d '{"name":"Alarm panel","scopes":["alerts:write","cameras:read"],"expires_in_days":365}'
  3. Store the key

    The response holds the full key in key. It is shown only once: store it in your integration or a password manager now.

expires_in_days (1–3650) or expires_at (at most 10 years ahead) set an expiry; without either the key never expires. List your keys with GET /api/v1/api-keys and revoke one with DELETE /api/v1/api-keys/{key_id}. Admins can list and revoke anyone's keys with ?user_id=.

Scopes#

A scope is a permission for one family of operations. Give a key only the scopes its integration needs.

ScopeGrants
cameras:readList and get cameras, live snapshots, a camera's AI services, audio and stream health, and vigiora-clients (admins, operators). Object recognition on a camera frame or an uploaded image (detect-objects, images/analyze). Signed live stream and snapshot links (stream-url, snapshot-url), and the Things list.
cameras:writeAdd, change, delete, enable and disable cameras, turn AI on and off, change many cameras at once, switch and set a camera's AI services, reference frames, rooms and speakers, and manage vigiora-clients (admins). Includes cameras:read.
cameras:controlPTZ: move, stop, list, save and go to presets, and move a room's camera. Speak and play audio in a room or through a camera's own speaker (cameras/{camera_id}/actions/speak), and test a speaker. Includes cameras:read. Separate from cameras:write, so a joystick integration can't edit cameras.
alerts:readList and get alerts, the unacknowledged-alert summary (GET /alerts/summary), alert snapshots, recognised faces and their photos, alert rules (camera and room rules), a camera's detection events (with the add-ons' reports) and object tracks, people counts and motion levels.
alerts:writeAcknowledge and unacknowledge alerts, one or in bulk, send alerts from your own systems (POST /alerts), delete alerts, and create, change and delete alert rules. Includes alerts:read.
recordings:readList recordings, the timeline, the days with recordings, playback, a frame from the recordings (GET /cameras/{camera_id}/frame), an alert's recording, clip status and the clip list. Also needed for detect-objects on a recorded moment.
recordings:writeExport and delete clips, get clip download URLs, protect and unprotect recordings. Includes recordings:read.
clips:shareList, create and revoke public share links, and live share links of a camera (API 1.109.0). No other scope includes it, except admin.
account:read, account:writeFrom API 1.107.0: the caller's own two-factor status and signed-in devices (account:read), and signing a device out (account:write). Turning two-factor on or off needs a user session, never a key. OAuth connections (MCP) are never granted these scopes.
guardian:read, guardian:writeRead and search the Guardian log (also per room), an entry's frame and clip, Recently deleted moments (admins, operators), the clip and trash settings, speech transcripts, Guardian conversations and the Briefing. guardian:write adds Guardian chat, analysing a camera now, describing an uploaded image, AI Live, compare and plate reading, which use AI credits, and the Briefing's review marks. It also deletes, restores and purges moments, and recomputes pictures and clips (admins, operators; purge and recompute admins only).
memory:read, memory:writeWhat Guardian remembers about you: memory:read lists and reads the facts kept for the key's own user, memory:write corrects and forgets them. memory:write includes memory:read.
analytics:read, analytics:writeAnalytics: counting lines, zones, areas and a camera's analytics settings, and counts, occupancy, dwell and heatmaps. analytics:write creates, changes and deletes lines, zones and areas, changes a camera's analytics settings and sets an area's occupancy (admins, operators). Includes analytics:read.
floorplans:read, floorplans:writeFloor plans: plans, their images, placed items and the live view, and where a camera is placed. floorplans:write creates, changes and deletes plans and replaces their items (admins, and operators who manage the site). Includes floorplans:read.
devices:read, devices:write, devices:controlHome Assistant devices shared with Vigiora through the bridge: devices:read reads the connection, the shared devices, room signals, triggers, rule actions and the action log; devices:write changes which devices are shared and how (selection admins only), camera and room links, room signals, triggers and rule actions; devices:control sends commands to devices. Admins and operators only. devices:write and devices:control include devices:read.
settings:read, settings:writeSites, rooms, layouts and layout sequences, system status, health and dashboard, the update, plan and remote access status (admins), the recording defaults, the configuration export (admins) and the Home Assistant install status (admins). settings:write creates, changes and deletes sites, layouts and layout sequences, changes the recording defaults, checks for an update, changes the Guardian clip pre-roll and how long deleted moments are kept, and installs, updates and connects Home Assistant (admins).
users:read, users:writeList users and groups; create, change and delete users and groups. Admins only.
events:readThe live event stream and the event log. Each event also needs the read scope of its family (for example alerts:read for alert events).
webhooks:read, webhooks:writeList webhooks and their deliveries; create, change, test, rotate and delete them. Admins' keys only. webhooks:write includes webhooks:read.
network:readScan the server's local network, list devices and look up the IP of a MAC address. Admins and operators only. It reads, but scans and lookups send traffic on the LAN, so no read-only access includes it. See Network tools.
adminEverything above, plus the configuration import, exporting camera passwords (encrypted with a passphrase), and naming and deleting faces.

A few operations need a user session and refuse every key (403 api_key_not_allowed): API keys, connected apps, costs and billing, AI service instances, external AI tools and switching remote access. The API reference marks them User session only. They are not MCP tools either.

Rules for creating keys:

  • admin, users:read, users:write, settings:write, webhooks:read and webhooks:write can only be given to an admin's key.
  • cameras:write, cameras:control, network:read, analytics:write, floorplans:write and devices:* can't be given to a viewer's key, because their operations need the admin or operator role.
  • A share link created with a key lives no longer than the key: it is revoked when the key is revoked and expires when the key expires.

What decides if a call is allowed#

A call is allowed only if all three allow it:

  1. The key's scopes include the operation's scope (sessions have every scope),
  2. and the user's role is one the operation accepts (admin, operator or viewer),
  3. and the user's permission on the camera is high enough (viewer, operator or manager; admins have every permission).

The role and permissions are read from the user on every request, so a role change or a disabled user takes effect at once.

Fails onAnswer
Scope403 insufficient_scope, with details.required_scope and details.granted_scopes
Role403 forbidden
Camera permission, and the camera is not visible to the user404 not_found
Camera permission, the camera is visible403 forbidden
An operation that needs a user session, called with a key403 api_key_not_allowed

Something you may not see always answers 404, never 403, so the API doesn't reveal what exists.

Keys without scopes#

Keys created before scopes existed, and keys from Settings → People and access → API keys, have no scopes ("legacy keys", "scoped": false). They keep working on /api exactly as before, and on v1 they get implicit scopes from their read-only flag:

KeyScopes on v1
Read-onlycameras:read, alerts:read, recordings:read, guardian:read, memory:read, settings:read
Read-writeThe above, plus cameras:write, cameras:control, alerts:write, recordings:write, guardian:write, and settings:write while the key's user is an admin

A legacy key never gets users:*, events:read, clips:share, network:read, analytics:*, floorplans:*, devices:* or admin, so it can't do more on v1 than it could on /api.

Scoped keys work on /api/v1 only. On the internal /api they are refused with 403 and "code": "api_key_scoped".

Sign-in access (OAuth)#

AI apps that sign in through the MCP server get one of two fixed scope sets, chosen on the consent page:

AccessScopes
Read onlycameras:read, alerts:read, recordings:read, events:read, analytics:read, floorplans:read, devices:read
Read and controlThe above, plus cameras:write, cameras:control, alerts:write, recordings:write, network:read, analytics:write, floorplans:write, devices:control

A viewer's connection never gets the admin-and-operator scopes (cameras:write, cameras:control, network:read, analytics:write, floorplans:write, devices:*).

Credentials stay hidden#

Camera passwords never appear in v1 responses, for keys and sessions alike. A camera address comes back as rtsp://REDACTED@192.0.2.20:554/stream1. If you send such a value back unchanged in a PATCH, the stored password is kept.

Revocation#

A key stops working at once when it is revoked or expires, or when its user is disabled. A long response opened with a key, such as a video download, is closed within 30 seconds of the key being revoked. Repeated requests with wrong keys from one address are slowed down with 429 rate_limited.

在 GitHub 上编辑此页