Skip to content

Machine API and roles

Last updated 28 Nov 2026

Your app's backend can act as itself, with a token from the client credentials grant. With it, your app declares the roles it understands, and Accord offers exactly those roles to your organizations.

A token for your app ​

POST <issuer>/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=<client id>
&client_secret=<client secret>

The client may also authenticate with HTTP Basic. The answer:

json
{
  "access_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 3600
}

The token lasts one hour. Ask for a new one when it expires. It speaks only for your app, and only in its own environment. It stops working when the app is deactivated or the workspace is suspended. See Machine token for its claims.

Every app registered in the console may use this grant, because each one has a client secret. Keep the secret on your server.

Calling the machine API ​

The machine API is on the auth host, for every environment:

https://auth.nubisco.io/api/m2m/
Authorization: Bearer <machine token>

A missing or invalid token gets 401.

Declaring your roles ​

Accord never decides what a role allows. A role is a word, and your app's code decides what it means. So your app tells Accord which words it understands, in a manifest kept beside the code that enforces them, and sends it when it starts. The roles and the code that checks them then change in the same commit.

Once your app has declared its roles, your workspace's staff give each member of an organization one of them in your app, and the tokens carry it as app_role.

Allow it first ​

Your app needs the roles:write permission. A workspace owner turns it on in the console: open the app and tick May declare its roles (roles:write). Without it, PUT answers 403 insufficient_scope.

Send the manifest ​

PUT https://auth.nubisco.io/api/m2m/roles
Authorization: Bearer <machine token>
Content-Type: application/json
json
{
  "version": 1,
  "fallback": "viewer",
  "creator": "owner",
  "tenancy": { "enable": "staff" },
  "roles": [
    {
      "key": "owner",
      "rank": 30,
      "label": { "en": "Owner", "pt": "Proprietário" },
      "description": { "en": "Manages the account and everything in it." }
    },
    {
      "key": "editor",
      "rank": 20,
      "label": { "en": "Editor" },
      "description": { "en": "Creates and changes content." }
    },
    {
      "key": "viewer",
      "rank": 10,
      "label": { "en": "Viewer" },
      "description": { "en": "Reads everything, changes nothing." }
    }
  ]
}
json
{ "ok": true, "changed": true, "version": 1, "moved": 0 }

Sending the same manifest again changes nothing and answers changed: false, so it is safe to send on every start.

The fields ​

FieldWhat
versionA whole number from 1. Raise it for every change. A lower one, or a change under the same one, is refused
roles1 to 50 roles
roles[].keyThe role's identity, never shown: a lower case letter, then up to 39 of a-z, 0-9, _ and -
roles[].rankA whole number. Higher means more privileged
roles[].labelThe name people see, by language (en, pt, pt-BR). en is required. Up to 300 characters each
roles[].descriptionOptional, by language, like label
roles[].renamed_fromOptional. Old keys this role replaces. Everyone who held them moves here
roles[].retiredOptional. { "replaced_by": "<key>" } drops this role and moves its holders to another
fallbackThe least privileged role. Its rank must be lower than every other role's
creatorThe role given to whoever enables your app on an organization
tenancy.enableWho may enable your app on an organization: staff (your workspace's owners and admins, the default), self_serve (an organization's own owners and admins too), or none

Treat a role your code does not recognise as the fallback. That keeps an older build of your app safe while a newer manifest is live.

Renaming and removing a role ​

A label can change freely. A key is the role's identity, so changing one is a rename and must say so:

json
{
  "key": "author",
  "rank": 20,
  "label": { "en": "Author" },
  "renamed_from": ["editor"]
}

A role nobody holds can simply be left out. A role somebody holds cannot: say where its holders go with renamed_from on the new role, or with retired on the old one. moved in the answer is how many assignments moved.

Errors ​

StatuserrorWhy
403insufficient_scopeThe app does not have roles:write
400invalid_manifestThe shape is wrong. detail names the field
400invalid_role_keyA key does not follow the rule above
400duplicate_role_keyTwo roles share a key
400invalid_fallbackfallback is not one of the active roles
400fallback_not_lowestAnother role ranks the same as the fallback or lower
400invalid_creatorcreator is not one of the active roles
409version_not_raisedThe version is lower, or the same with different content
409role_in_useThe manifest drops roles people hold. roles lists them

Reading your roles ​

GET https://auth.nubisco.io/api/m2m/roles
Authorization: Bearer <machine token>
json
{
  "app_id": "<app id>",
  "name": "Portal",
  "slug": "acme-portal",
  "workspace_id": "<workspace id>",
  "version": 1,
  "role_scope": "tenant",
  "enable": "staff",
  "roles": [
    {
      "key": "owner",
      "rank": 30,
      "labels": { "en": "Owner", "pt": "Proprietário" },
      "descriptions": { "en": "Manages the account and everything in it." },
      "is_fallback": false,
      "is_creator": true,
      "aliases": []
    }
  ]
}

No permission is needed to read your own app's roles. roles is ordered from the highest rank down. aliases lists old keys that still map to the role after a rename.

Accord is proprietary software by Nubisco.