Documentation / LemmeSee Hub

Plugin API keys

A plugin key is an access key limited to one or more plugins. It acts as the user who created it, so it sees what that user sees, but the hub accepts it only on the paths of the plugins it's scoped to and a few shared paths. Use one when a program, or a friend's copy of a plugin's client, needs to call one plugin's API: if the key leaks, it can't be used to drive the rest of your hub.

Who can create them

A user needs the plugin_keys.mint permission to create plugin keys. The Developer preset includes it, and admins can switch it on or off for any user with the switch under Plugin keys in the user's Keys dialog on the Users page. Switching it off stops new keys being created; keys that already exist keep working until you revoke them.

Creating a key

On the Users page, click Keys on the user's row. Under Plugin keys, with the switch on, enter:

FieldMeaning
LabelA name to recognise the key by, such as who or what it's for.
ScopesThe plugins the key may reach, separated by commas. Use each plugin's name (its file name without .py).

Click Create. The hub shows the key once, together with the scopes it works for. Copy it now: like every access key, the hub keeps only a hash and can't show it again.

The list shows each key's label, marked revoked when it is, its scopes, and when it was last used.

Users with the permission can also create their own keys through the API:

curl -X POST http://localhost:8765/api/users/plugin-keys \
  -H "X-Access-Key: YOUR_ACCESS_KEY" -H "X-Username: alice" \
  -H "Content-Type: application/json" \
  -d '{"label": "Build monitor", "scopes": ["demo"]}'

The response includes the key record plus access_key (shown only this once), mqtt_username and hub_server_id. Both label and at least one scope are required.

What a key can reach

On the hub's web address, a plugin key is accepted on:

  • Paths under /plugins/<scope>/ for each of its scopes.
  • Paths a scoped plugin opens to its keys, which may include paths of plugins it uses.
  • /api/users/me, /api/users/plugin-keys (so the holder can see and revoke their own keys) and paths under /api/feeds/ (a single feed's items and topics).

Anything else answers 403 with "This key is not authorised for this path". Inside those paths the key still has only its user's permissions.

Using a key

Send the key in the X-Access-Key header. Unlike a user's own access key, a plugin key doesn't need an X-Username header.

curl http://localhost:8765/plugins/demo/ -H "X-Access-Key: YOUR_PLUGIN_KEY"

The same key signs in to the MQTT broker. Use plugin_key_<id> as the username (the mqtt_username you got when creating it, also returned by /api/users/me when called with the key) and the key as the password. On the broker, a plugin key can read only the topics its scoped plugins publish, and within those only what its user may see.

Revoking and deleting

Revoke stops a key working. The hub refuses it from then on, and the broker refuses it at its next connection. The key stays in the list, marked revoked, until you Delete it. Holders can revoke and delete their own keys; admins can do it for anyone.

Deleting a user removes all their plugin keys too.

When a key is refused

Every refused request is recorded in the hub's User Authentication feed, with the path, the key's label and scopes, and what to change. See Troubleshooting.