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/jsonjson
{
"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
| Field | What |
|---|---|
version | A whole number from 1. Raise it for every change. A lower one, or a change under the same one, is refused |
roles | 1 to 50 roles |
roles[].key | The role's identity, never shown: a lower case letter, then up to 39 of a-z, 0-9, _ and - |
roles[].rank | A whole number. Higher means more privileged |
roles[].label | The name people see, by language (en, pt, pt-BR). en is required. Up to 300 characters each |
roles[].description | Optional, by language, like label |
roles[].renamed_from | Optional. Old keys this role replaces. Everyone who held them moves here |
roles[].retired | Optional. { "replaced_by": "<key>" } drops this role and moves its holders to another |
fallback | The least privileged role. Its rank must be lower than every other role's |
creator | The role given to whoever enables your app on an organization |
tenancy.enable | Who 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
| Status | error | Why |
|---|---|---|
| 403 | insufficient_scope | The app does not have roles:write |
| 400 | invalid_manifest | The shape is wrong. detail names the field |
| 400 | invalid_role_key | A key does not follow the rule above |
| 400 | duplicate_role_key | Two roles share a key |
| 400 | invalid_fallback | fallback is not one of the active roles |
| 400 | fallback_not_lowest | Another role ranks the same as the fallback or lower |
| 400 | invalid_creator | creator is not one of the active roles |
| 409 | version_not_raised | The version is lower, or the same with different content |
| 409 | role_in_use | The 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.