Three kinds of token
| Token | Comes from | Tells you | How to recognise it |
|---|---|---|---|
| ID token | /token, authorization code | Who signed in, for your app | No token_use claim |
| Access token | /token, authorization code | Who signed in, with their role | token_use is access |
| Machine token | /token, client credentials | Your app, acting as itself | gty is client_credentials |
All three last one hour (exp is iat plus 3600).
Checking a token
Before your app lets anybody in, check all of these:
- The signature, with the key from your issuer's key set whose
kidthe token names, andalgRS256only. iss, byte for byte against your issuer,https://auth.nubisco.io/e/<environment id>. Never derive it from a host name.aud, against your client id. A token for another app, or from your staging environment, fails here or at the signature.exp, against the clock.noncein an ID token, against the one you sent.- That it is a person's token. Never accept a machine token as a sign-in.
With the jose library in Node.js:
ts
import { createRemoteJWKSet, jwtVerify } from "jose";
const issuer = "https://auth.nubisco.io/e/env_0123456789abcdef0123";
const jwks = createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`));
export async function verifyIdToken(token: string, nonce: string) {
const { payload } = await jwtVerify(token, jwks, {
issuer,
audience: process.env.ACCORD_CLIENT_ID,
algorithms: ["RS256"],
});
if (payload.nonce !== nonce) throw new Error("nonce mismatch");
if (payload.token_use !== undefined) throw new Error("not an ID token");
return payload;
}createRemoteJWKSet caches the key set and fetches it again when a token names a kid it has not seen, which is what the key ring needs.
ID token
| Claim | What |
|---|---|
iss | Your issuer |
sub | The person's id in this environment. It does not change |
aud | Your client id |
email | The person's email address |
email_verified | Always true: the person proved it with an emailed code |
name | The person's name, or null when they have not given one |
locale | The person's language, with the profile scope (below) |
auth_time | When the person signed in, in seconds |
nonce | The nonce you sent to /authorize, if you sent one |
iat, exp | Issued at, and expiry |
Plus the organization claims for an app whose people come from organizations.
The person's language
locale is the language the person chose to read, as a BCP 47 tag such as pt-PT or en. It is there only when your app asked for the profile scope, and only when the person chose a language. A person on "Automatic" has no locale claim at all, never an empty one: speak the browser's language to them, as you would without Accord.
Use it as the person's language from the moment they sign in. The tag may name a language or region your app does not have, so match it by base language (pt-BR is still Portuguese) and fall back to the browser. The value in a token is the one at sign-in. Userinfo answers the one saved now.
Access token
| Claim | What |
|---|---|
iss, sub | As in the ID token |
aud, azp, client_id | Your client id |
token_use | access |
app_id | Your app's id in Accord |
app | Your app's slug, <workspace slug>-<app slug> |
scope | The scopes granted, separated by spaces |
email, email_verified, name | As in the ID token |
locale | As in the ID token |
role | The person's role in your app. member unless changed |
iat, exp | Issued at, and expiry |
Plus the organization claims below.
Organization claims
For an app whose rule is Members of organizations that use it, both tokens carry:
| Claim | What |
|---|---|
orgs | Every organization of the person's that uses your app (see below) |
org_id | The organization this sign-in is for |
org_slug | Its slug |
org_role | The person's role in the organization: owner, admin or member |
app_role | The person's role in your app in this organization, once your app has declared its roles |
Each entry of orgs has id, slug, name, role (in the organization), ref (your app's own id for the organization, or null) and, once your app has declared its roles, app_role.
For an app open to anyone with an Accord account, the tokens carry orgs, which is empty when the person belongs to no organization that uses the app. org_id, org_slug, org_role and app_role appear when the sign-in named an organization, or when the person belongs to exactly one.
json
{
"iss": "https://auth.nubisco.io/e/env_0123456789abcdef0123",
"sub": "<person id>",
"aud": "<client id>",
"token_use": "access",
"app": "acme-portal",
"email": "ada@example.com",
"email_verified": true,
"role": "member",
"org_id": "org_0123456789abcdef0123",
"org_slug": "example-corp",
"org_role": "admin",
"app_role": "editor",
"orgs": [
{
"id": "org_0123456789abcdef0123",
"slug": "example-corp",
"name": "Example Corp",
"role": "admin",
"ref": null,
"app_role": "editor"
}
],
"iat": 1795000000,
"exp": 1795003600
}Machine token
| Claim | What |
|---|---|
iss | Your issuer |
sub | Your client id |
client_id | Your client id |
app_id | Your app's id in Accord |
aud | Your app's slug |
token_use | access |
gty | client_credentials |
iat, exp | Issued at, and expiry |