Guides
Roles and permissions
Define roles once, read them from every token, and change them from your server.
Every platform has its own roles and permissions. You define them once in the console; loginos puts them in every token, on every one of your domains, and you change who has what from the console or from your server.
Jane’s roles
Tap to try your own mix.
{ "sub": "9b1f6c2e-…", "preferred_username": "jane", "roles": [ "member" ], "permissions": [ "comments:write", "posts:read" ]}Define them
In the console’s Roles tab:
- Permissions are what your code checks. Keys like
posts:publish: lowercase letters, digits and_ . : -, starting with a letter, up to 64 characters. - Roles group permissions. Keys like
editor: lowercase letters, digits,_and-, starting with a letter, up to 40 characters. Each role also has a display name, which people see on their loginos dashboard. - Default roles are given to everyone who joins your platform.
Read them
The user object from the token endpoint, the ID token and /oauth/userinfo all carry role keys and the permissions those roles grant:
{
"sub": "9b1f6c2e-5d1a-4b7e-9a51-0e6f3f6c1d2a",
"preferred_username": "jane",
"roles": ["editor", "member"],
"permissions": ["comments:moderate", "comments:write", "posts:read", "posts:write"]
}Check permissions rather than roles. Then a new role, or a role that gains a permission, needs no code change:
type User = { roles: string[]; permissions: string[] };
export const can = (user: User, permission: string) => user.permissions.includes(permission);
if (!can(session.user, "posts:write")) return new Response("Forbidden", { status: 403 });Roles and permissions are always included, whatever scopes you asked for. Tokens carry the roles someone had when they signed in; for the current ones, call /oauth/userinfo with their access token or read them from the Management API.
Change them
From the console (Users tab, open someone, tick their roles), or from your server:
curl -X PUT https://loginos.io/api/v1/users/SUB/roles \
-u "YOUR_APP_KEY:YOUR_APP_SECRET" \
-H "content-type: application/json" \
-d '{"roles": ["editor", "member"]}'The list replaces the person’s roles. Unknown keys are refused with unknown_role. GET /api/v1/roles lists your roles with their permissions.
Blocking
Blocking is not a role: a blocked member can’t sign in to any of your domains, and their tokens stop working at once. Block from the console or with POST /api/v1/users/{sub}/block. Their roles are kept for when you unblock them.